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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With