0

I have several documents in Firestore, each of which contain a map of user IDs. For example:

// Document 1
userIds: {
    "1": true,
    "2": true,
    "3": true,
    ...
}

// Document 2
userIds: {
    "2": true,
    "3": true,
    ...
}

// Document 3
userIds: {
    "2": true,
    "3": true,
    "4": true,
    ...
}

I would like to find all documents whose userIds map do not contain a certain user ID. I've tried using this query:

.where('userIds.1', isEqualTo: null)

However this doesn't get the intended result. With the above query, all documents are returned. Documents 2 and 3 should instead be returned.

How can I achieve this?

user2181948
  • 1,646
  • 3
  • 33
  • 60

1 Answers1

1

You can't query for the absence of data in a document. That's not the way a Firestore index works. Indexes work by recording the presence of values in a structure that's easy to search. They cannot store the near-infinite number of values that don't exist. If you want to search for something, it actually has to have a value in a known location.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441