Akhilesh Mani
Akhilesh Mani

Reputation: 3552

Android Google Firestore - Listen Multiple Documents

I am trying to listen multiple documents of Google Firestore at once.

Example: I have to listen the updates of documents A(id:1010), B(id:1020), and C(id:1030) only. All these documents have an ID field associated with them. I make my query like this.

 Query query = mCollectionReference.whereEqualTo("id", "1010");
 query = query.whereEqualTo("id", "1020");
 query = query.whereEqualTo("id", "1030");
 query.addSnapshotListener(this);

The problem here is, it doesn't listen to anything when I put multiple whereEqualTo condition, but for a single whereEqualTo it works fine.

So, is there any way to listen to multiple documents at once like using whereEqualTo with IDs in documents?

Any solution to read multiple documents is welcome.

Upvotes: 1

Views: 208

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317362

So, is there any way to listen to multiple documents at once like using whereEqualTo with IDs in documents?

No. But you can use an "in" query to specify multiple documents in an array, up to 10, to query or listen at the same time. If you need more than 10, you will need multiple queries.

Query query = mCollectionReference
  .whereIn("id", Arrays.asList("1010", "1020")));
query.addSnapshotListener(this);

Upvotes: 2

Related Questions