Firestore not listing documents which doesn’t have fields instead having sub collections

I am working on an attendance project. So, I have nested documents and collections. But problem is that:

Firestore not listing documents that don’t have fields. Firebase db structure Pic it only listing documents that have fields.

I am doing this in JavaScript.

db.collection("Attendence").get().then((querySnapshot) => {
querySnapshot.forEach((doc) => {
    // doc.data() is never undefined for query doc snapshots
    console.log(doc.id, " => ", doc.data());
});

});


Answer

Firestore not listing documents that don’t have fields.

That’s the expected behavior. The documents that I see listed in italics (“CG1”, “CSE A1”, and “DG2”) are not actually documents present in the collection.

The documents that are present in the “Attendence” collection and are writen in italics mean that there exist some subcollections with other documents added under those document IDs.

There is no query that can return those documents since they don’t exist. So in other words, you have just reserved some IDs for some documents in that collection and then create a subcollection under it. These kinds of documents are visible in the Firebase Console because you might want to navigate into their subcollections.

One thing to remember, in Cloud Firestore documents and subcollections don’t work like filesystem files and directories. If you create a subcollection under a document, it doesn’t implicitly create any parent documents. Subcollections are not tied in any way to a parent document.