users
|
|_ john_doe199
| |
| |_ subscriptions
| |
| |__ service_id1 : true
|
|_ jane_doe123
|
|_ subscriptions
|
|__ service_id1 : true
|__ service_id2 : true
根据此架构,如何找到订阅service_id1
的用户?
答案 0 :(得分:2)
这是Eirik回答的替代方案
usersRef.queryOrderedByChild("subscriptions/service_id1").queryEqualToValue(true)
.observeSingleEventOfType(.Value, withBlock: { snapshot in
print(snapshot)
})
答案 1 :(得分:1)
您可以这样做:
let ref = Firebase(url: "https://<your_app>.firebaseio.com/users")
ref.queryOrderedByChild("subscriptions/service_id1")
.observeEventType(.ChildAdded, withBlock: { snapshot in
if let subscribed = snapshot.childSnapshotForPath("subscriptions/service_id1")
.value as? Bool {
print("\(snapshot.key) is subscribed to service_id1: \(subscribed)")
}
})