Firebase Database Structure - Users, Groups And Lists
Solution 1:
The Firebase Database documentation recommends keeping your data flat, not nesting unrelated types of data. It seems you're trying to do that, so that sounds good.
If you flatten your data, you will need to have a way to relate items in the various lists with each other. The simplest way to do that is by giving the corresponding items the same key in all lists. They're like PK/FK in a relational database, except that Firebase (unlike most relational DBMSs) doesn't manage the relation for you.
The topic of data modeling is incredibly broad and it's hard to do it justice in a Q&A format. I highly recommend reading NoSQL data modeling and viewing our Firebase for SQL developers series. You'll also find a lot of data modeling questions in this list.
Solution 2:
Sorry I can't post a comment. I would recommend to make your life easier to have the same ID each of the data. Also, look into userIDs and PushID, they might come handy.
To get push id you can:
DatabaseReferencemypostref= databaseRef.push();
mypostref.setValue(data);
String mypostref.getKey());
and you get userID:
private FirebaseAuth mAuth;
mAuth = FirebaseAuth.getInstance();
FirebaseUseruser= mAuth.getCurrentUser();
user.getuID
Have something like this:
{
"users": {
"userID": {
PushID: {
"userName":..."email":..."group":groupID"creationTime":...userID:....pushID....
}
}
}
},"groups": {
"userID": {
PushID: {
"name":..."members": {
"userID":true"userID":trueuserID:....pushID....
}
}
}
},"lists": {
"userID": {
PushID: {
"name":..."items": {
"itemID":true"itemID":trueuserID:....pushID....
}
}
}
},"items": {
"userID": {
PushID: {
"name":..."createdBy":userID"timeCreated":...pushID....
}
}
}
}
Think of userID as your primary key and pushID and unique identifier. There can be one user (uID) who can have many data under them (pushID)
Post a Comment for "Firebase Database Structure - Users, Groups And Lists"