0

I'm new to firebase and databases in general so pardon me if it's something trivial. My collection looks like this:

Rooms{
  Room1{
    roomName,
    user1,
    user2,
  },...
}

I wanted to filter the results so I can get only rooms that have user1 field different than id of the current user and user2 equal to an empty string.

I've read that there is no OR in firestore queries, you can't do it like this

const openRoomsQuery = roomsRef.where("user1", "!=", user.uid).where("user2", "==", "");

nor like this

const notMineRoomsQuery = roomsRef.where("user1", "!=", user.uid);
const openRoomsQuery = notMineRoomsQuery.where("user2", "==", "");

How can I do this in a fairly simple way (possibly without putting user fields to a single array field)?

Mirz
  • 23
  • 4
  • This type of query is not supported by Firestore. You can only compare fields to specific values provided in the where clause. – Doug Stevenson Nov 10 '20 at 17:01
  • What do you mean? I've done it both ways I provided code for. I just wasn't using "!=" in those. It worked fine. (Oh yeah. It didnt work for a second one I guess. Sorry) – Mirz Nov 10 '20 at 17:04
  • I think I misread the question, but the disposition is the same - Firestore does not support logical OR queries. You have to perform two queries and merge the results in the app. Your question is effectively a duplicate of this: https://stackoverflow.com/questions/46632042/how-to-perform-compound-queries-with-logical-or-in-cloud-firestore – Doug Stevenson Nov 10 '20 at 17:12

0 Answers0