0
votes

This is the Firestore collection with custom document IDs which are actually dates as string. The purpose of this kind of custom id is fetching the documents of particular date.

enter image description here

Here's the code :

FirebaseFirestore.getInstance().collection("Users")
                    .document(FirebaseAuth.getInstance().getUid())
                    .collection("Bookings By Date")
                    .get().addOnCompleteListener(new 

OnCompleteListener<QuerySnapshot>() {
                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {
                    if (task.isSuccessful()) {
                        Log.d(TAG, "onComplete: called");
                        Log.d(TAG, "onComplete: task result = " + task.getResult());
                        Log.d(TAG, "onComplete: task.getResult().getDocuments().size() = " + task.getResult().getDocuments().size());
                        QuerySnapshot queryDocumentSnapshots = task.getResult();

            }
        }
    });

enter image description here Here are Logcatlogs where task.getResult().getDocuments().size() is returning 0 it should return 3 as i have 3 documents in the collection.

2

2 Answers

2
votes

Issue resolved. If a firestore document doesn't have any field in it then CollectionReferece#get() method skip those documents.

enter image description here

2
votes

A document can actually be empty in Firestore, meaning that it is possible to have a document without data, and your code would load that.

In this case however, in your screenshot you can see that 1-4-2019 document name is is displayed in italics, which means that this document doesn't exist. The console merely shows this name in the list, because there are subcollections under that path. And since document 1-4-2019 doesn't exist, it won't be returned when you load all documents.

In short:

  • A document can be empty, meaning that you can have a document without any data fields.
  • All documents (including empty ones) are returned when you read all documents from a collection.
  • If there are subcollections under a path for which no document exists, the Firestore console will show that non-existing document's title in italics.
  • Non-existing documents are not returned when you read all documents from a collection.

Also see: