6
votes

I am trying to GET data from Firestore but I cannot see data coming. I am building a react-native app. I am using react-native-firebase.

I also tried Transactions method from react-native-firebase documentation. But nothing is working.

Here' my code:

firebase.firestore().collection('users').doc(uid)
          .get()
          .then((doc)=>{ 
                  console.log(doc)
                  console.log(doc.data().shoppinglist)   
          })
          .catch(e => console.log(e));

Console logging .get() gives me a Promise.

I am getting the Promise like this:

Promise {_40: 0, _65: 0, _55: null, _72: null}
_40: 0
_55: null
_65: 0
_72: null

But .then() doesn't executes as the two console.log() ain't logging anything.

Please help me out here. Quite new with Firebase.

1
maybe you don't have such collection?Alexandr Zavalii
ofcourse I do Sir. I'm able to write data on that collection.Saumay Paul

1 Answers

7
votes

After some digging in Firebase Documentation, I found out a solution.

Collection references and document references are two distinct types of references and let you perform different operations. For example, you could use a collection reference for querying the documents in the collection, and you could use a document reference to read or write an individual document.

Therefore, Replacing firebase.firestore().collection('users').doc(uid) with firebase.firestore().doc(`users/${uid}`) solved my problem.