0

I know firestore doesn't allow inequality statements in .where() queries and I should instead chain > and < queries, but I don't know how this will work in my case.

In my react native app, I want to select some users who have not been already added by the user. After getting an array of all the users the current user has already added as so:

var doc = await firebase
  .firestore()
  .collection(`users/${currentUser.uid}/user_data`)
  .doc("friends")
  .get();
var friends = doc.data()

I then want to choose some users who have not been added by the current user as so:

var docs = await firebase
  .firestore()
  .collection("users")
  .limit(10)
  .where("username", "not in", friends)
  .get();

How would I do this? Thanks

M. Alex
  • 673
  • 5
  • 26

1 Answers1

0

This kind of query is not possible with Firestore. Firestore can only query for things that exists in the indexes that it creates for each field. These indexes can't be queried efficiently for things that don't exist.

See also: Firestore: how to perform a query with inequality / not equals

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • This question shows to get documents where a field isn't equal to a single string. But I want to know how to get documents where a field isn't any of an array of strings. How do you recommend doing this? – M. Alex Jul 30 '20 at 19:57
  • It can't be done for the same reason. The data type doesn't matter. List, map, string, number, timestamp, all of them can't be checked for non-existence. That's not how the indexes work. – Doug Stevenson Jul 30 '20 at 20:11