1

I'm writing a chat app using a Firebase database. I need to query my data to find the messages to show to the user. I am currently using queryEqual to find all the posts FROM the specified user:

databaseRef.child("posts").queryOrdered(byChild: "uid").queryEqual(toValue: FirebaseManager.currentUser?.uid)

This returns all the posts sent from the logged in user, but doesn't return anything sent TO the logged in user. I can get the messages sent to the logged in user by changing 'uid' to 'toId' as follows:

databaseRef.child("posts").queryOrdered(byChild: "toId").queryEqual(toValue: FirebaseManager.currentUser?.uid)

But how can I combine the two into one query that says "give me all the posts where either 'uid' or 'toId' is equal to this value"?

Here is my database:

database

Mike Miller
  • 3,368
  • 5
  • 36
  • 49

0 Answers0