I have a service that creates collections based on id and saves necessary data to them. I want to return all of these collections without knowing their name or id. I tried several ways but every time I access the top collection and its contents. Is there a way to reach all collections?
As you can see in the picture below, I have two collections starting with ckJCeY...
and one starting with fzwKx...
but unfortunately I can only access the one starting with ckJCeY....
Here is my code:
public List<Currency> getRemindedCurrencies() throws ExecutionException, InterruptedException {
String key = "deviceKey";
Firestore db = FirestoreClient.getFirestore();
Iterable<CollectionReference> collectionReferences = db.listCollections();
Iterator<CollectionReference> iterator = collectionReferences.iterator();
List<Currency> currencyList = new ArrayList<>();
HashMap<String, List<Currency>> deviceKeyCurrencyListMap = new HashMap<>();
if (iterator.hasNext()) {
CollectionReference next = iterator.next();
for (Currencies currencies : Currencies.values()) {
DocumentReference document = next.document(currencies.name().toLowerCase() + "-reminder");
ApiFuture<DocumentSnapshot> snapshotApiFuture = document.get();
DocumentSnapshot documentSnapshot = snapshotApiFuture.get();
if (documentSnapshot.exists()) {
String keyVal = documentSnapshot.getData().get(key).toString();
currencyList.add(documentSnapshot.toObject(Currency.class));
deviceKeyCurrencyListMap.put(keyVal, currencyList);
if (deviceKeyCurrencyListMap.containsKey(key)) {
deviceKeyCurrencyListMap.get(keyVal).add(documentSnapshot.toObject(Currency.class));
}
} else {
continue;
}
}
}
return currencyList;
}