【发布时间】:2014-11-06 01:52:12
【问题描述】:
我来自 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"
}
}
}
}
}
}
【问题讨论】:
标签: javascript firebase firebase-realtime-database nosql