0

I want get all docs from a collection but on my code nothing is returned like I can see on the log printing the snapshot returned. I can use Storage on my application to store documents, and I can write on Firestore documents too, so the Firebase is correct configured, but it's not reading the docs.

getUsers() {
  firebase
    .firestore()
    .collection("users")
    .get()
    .then(function(querySnapshot) {
      console.log(querySnapshot);
      querySnapshot.forEach(function(doc) {
        console.log(doc.id, " => ", doc.data());
      });
    });
}

enter image description here enter image description here

1 Answer 1

1

This is working as expected. The query you're performing is only going to get documents immediately in the users collection. However, the screenshot her shows that there are not actually any documents in that collection. The document IDs you see in that collection are in italics, which means there is no document there, HOWEVER, there is at least one subcollection ("data") under that document.

Firestore queries are shallow, meaning that they only consider documents immediately within the collection you're trying to query. Documents in subcollections are not considered. Missing doucuments that have nested subcollections are also not considered (since they are not actually documents).

If you want to be able to query documents in a collection, you must actually write a document there. Documents in subcollections do force a parent document to exist.

Sign up to request clarification or add additional context in comments.

1 Comment

If you have a collection containing italics IDs which contain 2 or 3 subcollections each, how do you iterate through those?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.