0
const q = query(collection(db, "products"), where(documentId(), 'in', listOfIds))
const querySnapshot = await getDocs(q);

I am trying to do a query in a collection where their documentId exists in a list of ids, but I got an error:

Uncaught (in promise) FirebaseError: Invalid query. When querying with documentId(), you must provide a valid string or a DocumentReference, but it was: a custom rf object.

not sure if it's relevant, but my firebase-admin version is 11.8.0

If querying documentId in a list is not supported, what's the best workaround to filter documents in a collection where their documentId exists in another collection?

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Derek
  • 13
  • 3

1 Answers1

0

You're getting the following error:

Uncaught (in promise) FirebaseError: Invalid query. When querying with documentId(), you must provide a valid string or a DocumentReference, but it was: a custom rf object.

Because the listOfIds object is not a string, nor a DocumentReference object, as the function requires. The in operator lets you combine multiple equality (==) clauses on the same field with a logical OR, not a document ID. So what you're trying is currently not possible.

What you can do is save the document ID as a field inside the document, and then use the in operator.

Or as @DougStevenson mentioned in his comment, you can fetch each document individually while you iterate the list.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193