构建 firebase 数据库,依赖于两个变量
Structuring firebase database, dependency on two variables
我在构建数据库时遇到了一些问题。
目前我的用户和组结构如下:
-groups
-groupId
-groupname: "...."
-users
-userId: true
-users
-userId
-username: "..."
-groups
-groupId: true
现在我想添加依赖于组和用户的变量。我尝试制作另一棵名为 groupUser
的树,其中包含 groupId
和 userId
,但很难使用 Firebase 在两个条件下进行查询。那么构建数据库的最佳方式是什么?
提前致谢!
我会像这样构建您的数据:
{
groups: {
groupIdOne: {
groupname: "...",
users: {
userIdOne: true
}
}
},
users: {
userIdOne: {
username: "...",
groups: {
groupIdOne: true
}
}
},
groupUsers: {
groupIdOne: {
userIdOne: {
//data for group users
}
}
},
//and/or
userGroups: {
userIdOne: {
groupIdOne: {
//data for user groups, same as above
}
}
}
}
这样,如果您有组 ID 和用户 ID,您只需通过 .child('groupUsers').child(groupId).child(userId)
之类的操作直接查询该节点
我在构建数据库时遇到了一些问题。 目前我的用户和组结构如下:
-groups
-groupId
-groupname: "...."
-users
-userId: true
-users
-userId
-username: "..."
-groups
-groupId: true
现在我想添加依赖于组和用户的变量。我尝试制作另一棵名为 groupUser
的树,其中包含 groupId
和 userId
,但很难使用 Firebase 在两个条件下进行查询。那么构建数据库的最佳方式是什么?
提前致谢!
我会像这样构建您的数据:
{
groups: {
groupIdOne: {
groupname: "...",
users: {
userIdOne: true
}
}
},
users: {
userIdOne: {
username: "...",
groups: {
groupIdOne: true
}
}
},
groupUsers: {
groupIdOne: {
userIdOne: {
//data for group users
}
}
},
//and/or
userGroups: {
userIdOne: {
groupIdOne: {
//data for user groups, same as above
}
}
}
}
这样,如果您有组 ID 和用户 ID,您只需通过 .child('groupUsers').child(groupId).child(userId)