0

I have such structure of DB: enter image description here

As you see I have two collections: 'Threads' and 'Users' I need to receive all threads where ownedId is wVlUM2Un9kNouOIlztKLvxxxPDh1 e.g.

3
  • 1
    What you need for this is a query. They covered in the Firebase documentation and some of these questions probably have good example too. Commented Aug 7, 2017 at 17:07
  • 1
    As 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. Commented Aug 7, 2017 at 17:12
  • @FrankvanPuffelen it seems you've already answered - stackoverflow.com/a/39647861/877223 Commented Aug 7, 2017 at 17:20

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.