我有一个数据库方案,其本质上是相同的文档 https://firebase.google.com/docs/database/ios/structure-data#fanout :
// An index to track Ada's memberships
{
"users": {
"alovelace": {
"name": "Ada Lovelace",
// Index Ada's groups in her profile
"groups": {
// the value here doesn't matter, just that the key exists
"techpioneers": true,
"womentechmakers": true
}
},
...
},
"groups": {
"techpioneers": {
"name": "Historical Tech Pioneers",
"members": {
"alovelace": true,
"ghopper": true,
"eclarke": true
}
},
...
}
}
我想创建一个DatabaseQuery
这得到属于特定组的所有用户(例如“组”包含“techpionneers”的用户)
我应该如何进行?我尝试了一个Database.database().reference(withPath: "users").queryOrdered(byChild: "groups").queryEqual(toValue: "techpioneers")
但这不起作用(显然)。
要加载属于特定组的所有用户,start in the /groups
节点找到它们的密钥:
ref.child("groups/techpioneers/members").observeSingleEvent(of: .value, with: { (snapshot) in
这将为您提供所有成员的密钥。然后循环这些键并加载相应的用户。
这本质上是一个客户端连接操作。虽然您最初可能认为这非常慢,但实际上并没有那么糟糕,因为 Firebase 通过单个连接管道传输请求。看http://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network-app-by-using-query-instead-of-obse/35932786#35932786 http://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network-app-by-using-query-instead-of-obse/35932786#35932786.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)