showtime
showtime

Reputation: 1462

how to fetch all docouments with an ID that doesnt exist in the given array? (Cloud Firestore)

I have an array of IDs. Now, I would like to fetch all documents that DO NOT exist in that array.

Lets say let array = ["id1", "id2", "id3];

and document IDs in Firestore: "id1", "id2", "id3", "id4", "id5".

So basically I need to fetch only the docs with "id4" and "id5";

I thought of using this but I am not sure how exactly:

const westCoastCities = citiesRef.where('regions', 'array-contains', 'west_coast').get();

I am new to Firebase so please be patient with me.

Upvotes: 1

Views: 283

Answers (1)

Yi Zhou
Yi Zhou

Reputation: 813

This should work

idsRef.where('ids', 'not-in', ["id1", "id2", "id3]);

You should always check their doc first https://firebase.google.com/docs/firestore/query-data/queries#not-in

Upvotes: 2

Related Questions