简体   繁体   中英

Get Firestore document where value not in array

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM