0

I'm trying to return all document IDs in a specific collection. I'm writing this in Javascript for a web application. I made this function, and call it where it is needed.

function getUserList() {
    var rootRef = firebase.database().ref();
        var db = firebase.firestore();
        //var docRef = db.collection("Users");//.doc(getUserID()).collection("userControl").doc("UserStatus") //EXAMPLE: /Users/UUID/userControl/UserStatus

        db.collection('Users')
        .get().then(function(querySnapshot) {
            size = querySnapshot.size // will return the collection size
            console.log(size);
            querySnapshot.forEach(function(doc) {
               console.log(doc.id);

            });
        });
}

However when I check the console log for the data, I only ever see 6 out of 8 documents. There are 8 documents total, but the count and log of doc.id only shows 6. can be seen in screenshot (blanked one ID out for reasons).

enter image description here

If I specify one of the missing documents .get.collection('Users').doc('UUID HERE')... it reads that document without issue.

Most of these documents are uploaded from an IOS app, with the exception of mine (blurred out), the UID template. If I manually edit the document, ie add an extra field, etc the document appears in the search, but for documents straight from the IOS app, they aren't appearing unless speficifed.

I'm not sure how to go about fixing this, or why this issue is occuring.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441

1 Answers1

0

The documents you see listed in italics ("AB47..." and "DCBC...") are not actually documents present in the collection. The italics means that there are subcollections with other documents organized under that document ID. No query will ever match those documents, since they don't exist. You might have deleted them without deleting all the documents in all of their subcollections. But they remain visible in the console because you might want to navigate into their subcollections.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Thanks. That makes sense. In order to fix this/make this work, I'd have too write the the document "AB47..." individually and not just with `collection("Users").document(userID).collection("collectionName").document(Doc'name')` when I write data. – Martin monis Mar 04 '20 at 02:19
  • Yes, if you wrote a subcollection organized under a document ID that doesn't exist, you would still have to manually create that document if you want it to appear in a query. – Doug Stevenson Mar 04 '20 at 02:21