I have a Firestore database where I'm trying to query some user information via the Android API, but it doesn't seem to return results.
The structure of my database looks like this:
/users/test_user/test_sub_collection/randomDocId
(main collection -> doc -> sub collection -> doc)
Here's the Java code:
FirebaseFirestore.getInstance()
.collection("users")
.document("test_user")
.collection("test_sub_collection")
.get()
.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
List<DocumentSnapshot> documents = task.getResult().getDocuments();
for (DocumentSnapshot doc: documents) {
if (doc.exists()) {
// And here lies the problem. The getData size is always zero,
// doesn't matter how many fields and subcollections
// I keep adding to the randomDocId.
doc.getData();
}
}
}
});
So to sum up, doc.getData().size()
always returns 0, even though doc.getId()
returns the correct id (randomDocId). randomDocId also has a field and sub collection.
I honestly don't have a clue what I'm doing wrong.