Home > Net >  Why the documents (that have further sub collection) size is 0 when you call .collection("collN
Why the documents (that have further sub collection) size is 0 when you call .collection("collN

Time:08-22

I have a similar problem as this question question, but no one has answered yet. I have a collection that has documents and those documents have further collections. When I try to get these documents I receive 0 documents. database image

Code

db.collection("teachers").document("irfany").collection("OpenAssignments").
        get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
    @Override
    public void onComplete(@NonNull Task<QuerySnapshot> task) {
        if (task.isSuccessful()) {
            Log.d("getdocumentSize", task.getResult().size()   " => ");

            for (QueryDocumentSnapshot document : task.getResult()) {

            }
        } else {
            Log.d("Error", "Error getting documents: ", task.getException());
        }
    }
});

Output D/getdocumentSize: 0 =>

CodePudding user response:

The Math 101 document in the provided screenshot does not exist (as indicated by the italic document ID) but there's a sub collection assignmentData in it. If you still want to query all document in OpenAssignments then it'll be best to add a field in the document to actually create it.

If your goal is to query assignmentData documents of all OpenAssignments then you can use a Collection Group query instead.

Also checkout: Firestore query returns no documents even though they are shown in the console in italics

  • Related