Unable to fetch data from Firebase Firestore in react native

点点圈 提交于 2021-02-07 06:59:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!