I need to fetch all the ids/keys of a collection in Cloud Firestore. Currently I do it like this (groovy):
ApiFuture<QuerySnapshot> snapshot = firestoreClient.database.collection(bucket).get()
List<QueryDocumentSnapshot> documents = snapshot.get().getDocuments()
for (QueryDocumentSnapshot document : documents) {
keys.add(document.id)
}
I run this on a collection which potentially has could have a lot of documents lets say 30.000 which causes a java.lang.OutOfMemoryError: Java heap space
The thing is that I don't need all the documents. As seen in my code all I need is to check which documents are in the collection (ie. a list of keys/id's), but I have not found any way to grab them with out fetching all the documents which has a huge overhead.
I using the Java Firebase Admin SDK (6.12.2).
So I'm hoping that there is a way to grab all the keys with out the overhead and without my heap maxing out.