I am using Firebase Firestore to query some documents with a certain id. This is my structure:
EDIT: SCREENSHOT AND DESCRIPTION ADDED JUST AFTER THIS LINE:
generatedId and id have the same value. I have a list of these "id" and I want to search the public_messages collection to return a list of items which my provided list of "id".
root
----- public_messages
---------- generatedId
-------------------- name
-------------------- id
---------- generatedId
-------------------- name
-------------------- id
----- other data
I am using the following code to query the messages with a certain id:
ArrayList<String> keys ... (this has some keys)
CollectionReference collectionReference = firebaseFirestore.collection("public_messages");
for (String id : keys) {
collectionReference.whereEqualTo("id", id);
}
collectionReference.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
int count = 0;
for (QueryDocumentSnapshot document : task.getResult()) {
count++;
}
loog("total messages = " + count);
} else {
Log.d("TAG", "Error getting documents: ", task.getException());
}
}
});
In onComplete, the variable task.getResult() returns all the documents in the said collection. Consequently, the variable count represents the total number of documents in the said collection.
I want to only query the results with the specified ids. The number of ids can exceed 10 (which is apparently the limit set by Google, and which limit I was trying to evade by using a for-loop). What should I do?
