问题
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:
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.
来源:https://stackoverflow.com/questions/55476263/unable-to-fetch-data-from-firebase-firestore-in-react-native