我来自 MySQL 工作流程,现在我正在尝试在 Firebase 中做一些事情,我在构建数据时遇到了一些困境,因为我不知道如何查询它。
在下面的例子中我有一些users
和一些comments
,什么是找到的好方法
how many post likes a user had
how many post comments a user had
what were the posts that a user liked
...
我正在考虑将这些信息添加给用户,例如:
"user:2": {
"name": "Doe",
"email": "doe@bob.com",
"post_likes": {
"post:1": 1,
"post:2": 1
},
"post_comments": {
"post:1": 15,
"post:2": 5
}
}
但这似乎是多余的并且重复数据..
我需要找到一种方法来搜索与 相关的posts
所有内容user:1
,也许我需要创建另一个连接users
和的对象posts
??
有任何想法吗?
{
"array": {
"users": {
"user:1": {
"name": "John",
"email": "john@bob.com"
},
"user:2": {
"name": "Doe",
"email": "doe@bob.com"
}
},
"posts": {
"post:1": {
"name": "First Post",
"content": "some post content",
"comments": {}
},
"post:2": {
"name": "Second Post",
"content": "some other post content",
"likes": 2,
"comments": {
"comment:1": {
"uid": "user:1",
"email": "some comment"
},
"comment:2": {
"uid": "user:2",
"email": "some other comment"
}
}
}
}
}
}