-1

How i can get data from array stored in collection?

Here's screen from my firestore.

I tried to log this array by

    const ref = await firestore
      .collection("users")
      .where("id", "==", key)
      .get();
    console.log(ref);

But ref in console tells me that empty: true and array is 0.

Any tips?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Does this help you: https://stackoverflow.com/questions/55476263/unable-to-fetch-data-from-firebase-firestore-in-react-native – Sinan Yaman Dec 24 '20 at 14:01
  • It's not clear what isn't working the way you expect. I suggest doing more than just logging `ref` - it's a QuerySnapshot object with an API that gives you query results. If you are trying to learn how to query Firestore, start with the documentation: https://firebase.google.com/docs/firestore/query-data/queries – Doug Stevenson Dec 24 '20 at 16:51

1 Answers1

3

You will get the user array under querysnapshot. Please check the attached code.

 firestore.collection("users").where("id", "==", key)
    .get()
    .then(function(querySnapshot) {
        querySnapshot.forEach(function(doc) {
            // doc.data() is never undefined for query doc snapshots
            console.log(doc.id, " => ", doc.data());
        });
    })
    .catch(function(error) {
        console.log("Error getting documents: ", error);
    });
sedhal
  • 522
  • 4
  • 13