Recommendations for data modeling in Firebase / AngularFire

This is the first time I'm developing an application in Firebase, and I was curious how I should simulate data between two objects, userand a post. I come from a more relational background db, and I was curious not only how it would be done in non-relational databases, but also specifically how to establish a connection between two objects in Firebase.

For example, in my application there are many users, and each user creates many messages.

User {
    firstName: String,
    lastname: String,
    userName: String
}

Post {
    title: String,
    content: String,
    date: Date,
    writtenBy: [User object?]
}

How should I structure these two objects in Firebase so that Post belongs to the User, but all messages can be requested independently of the user, and both User and Post objects can be edited without violating other object data and / or relationships?

"" firebase:

sync.$set({userA: {
   firstname: "Billy",
   lastName: "Bob",
   userName: "BillyBob",
   Posts: {
       // .....
   }
}
});

!

+4
2

Firebase . -, - . Firebase URL-, . , , . ( , ), , , :

User {
    userId(assigned by Firebase automatically) {
        firstName: String,
        lastname: String,
        userName: String
    }
}

Post {
    User {
        userId(matching userId in the User object) {
            postId(assigned by Firebase for every new post automatically) {
                title: String,
                content: String,
                date: Date,
                writtenBy: String, userName or userId (this is not really needed, but may keep it for easier data access)
            }
        }
    }
}

, , ( , ). :

var postListRef = new Firebase(URL);
var lastPostQuery = postListRef.child("Post").limit(500);

startAt() endAt() quesries https://www.firebase.com/docs/web/api/query/limit.html for, , , , .

, :

var postListRef = new Firebase(URL);
var lastPostQuery = postListRef.child("Post/User").child(userId);

Angular/AngularFire .

+9

Firebase, .

Users: {
  userID: {
    firstName: String,
    lastname: String,
    userName: String,
    posts: {
      postID1:true,
      postID2:true
   }

Posts: {
  postID1:{
    title: String,
    content: String,
    date: Date,
    writtenBy: userID
  }
}

- . , , .

0

All Articles