As you see I have two collections: 'Threads' and 'Users' I need to receive all threads where ownedId is wVlUM2Un9kNouOIlztKLvxxxPDh1 e.g.
3
-
1What you need for this is a query. They covered in the Firebase documentation and some of these questions probably have good example too.Frank van Puffelen– Frank van Puffelen2017-08-07 17:07:25 +00:00Commented Aug 7, 2017 at 17:07
-
1As Frank pointed out a query would likely be the easiest way to go about this. Another option would be to loop through the thread objects and add the threads with the correct id to an array.Echizzle– Echizzle2017-08-07 17:12:36 +00:00Commented Aug 7, 2017 at 17:12
-
@FrankvanPuffelen it seems you've already answered - stackoverflow.com/a/39647861/877223Aleksey Shevchenko– Aleksey Shevchenko2017-08-07 17:20:39 +00:00Commented Aug 7, 2017 at 17:20
Add a comment
|
1 Answer
Hi I had a similar scenario while working on a chatting application that used firebase as a backend service.
you can use a query as such, I did it through similar query
FireBase.Reference.threads
.queryOrdered(byChild: "ownerId")
.queryEqual(toValue: "YourUserId")
.observe(.value) { (snapshot) in
if let messages = snapshot.value as? NSDictionary {
// you will get all those threads where ownedId is what you need to fetch for
}
}
Hope this helps, please let me know if any corrections required.
