Reputation: 24998
users
|
|_ john_doe199
| |
| |_ subscriptions
| |
| |__ service_id1 : true
|
|_ jane_doe123
|
|_ subscriptions
|
|__ service_id1 : true
|__ service_id2 : true
Given this schema, how do I find users who are subscribed to service_id1
?
Upvotes: 1
Views: 58
Reputation: 35648
This is an alternative to Eirik's answer
usersRef.queryOrderedByChild("subscriptions/service_id1").queryEqualToValue(true)
.observeSingleEventOfType(.Value, withBlock: { snapshot in
print(snapshot)
})
And this is called a Firebase Deep Query
Upvotes: 2
Reputation: 111
You can do something like this:
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)")
}
})
Upvotes: 1