无法在React Native中从Firebase Firestore提取数据 [英] Unable to fetch data from Firebase Firestore in react native

查看:74
本文介绍了无法在React Native中从Firebase Firestore提取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Firestore获取数据,但是看不到数据.我正在构建一个本机应用程序.我正在使用react-native-firebase.

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.

我还尝试了react-native-firebase文档中的交易方法.但是什么都没用.

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

这是我的代码:

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

控制台日志.get()给了我一个承诺.

Console logging .get() gives me a Promise.

我得到这样的承诺:

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

但是.then()不会执行,因为两个console.log()不会记录任何内容.

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

请在这里帮助我.Firebase相当新.

Please help me out here. Quite new with Firebase.

推荐答案

经过挖掘在Firebase文档中,我找到了解决方案.

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

集合引用和文档引用是两种不同的引用类型,可让您执行不同的操作.例如,您可以使用集合引用来查询集合中的文档,并且您可以使用文档引用来读取或编写单个文档.

因此,将 firebase.firestore().collection('users').doc(uid) 替换为 firebase.firestore().doc(`users/$ {uid}`)解决了我的问题.

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

这篇关于无法在React Native中从Firebase Firestore提取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆