【发布时间】:2020-04-10 14:20:08
【问题描述】:
我正在尝试做世界上最简单的事情:从我的 firebase 数据库中检索文档,但事实证明这是不可能的。我正在使用 React Native 和 Expo。
我正在尝试做这样的事情:
import * as firebase from 'firebase';
// ... React component
useEffect(() => {
firebase.database().collection("users")
.where("geohash", ">=", lower)
.where("geohash", "<=", upper)
.get()
.then((docs) => console.log(docs));
}, []);
我目前收到以下错误:
firebase.database().collection is not a function.
到目前为止我已经尝试过什么
This question 说将firebase.database() 更改为firebase.firestore(),但是,这不仅对我不起作用,而且我还在我的应用程序的其他部分使用firebase.database().ref("/users/" + uid).set() 和firebase.database()ref("/users/" + uid).update() 没有问题,所以我不要认为我应该将其更改为firebase.firestore()。当我确实改变它时,它仍然会抛出一个错误:
Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=not-found]: The project test-app8768 does not exist or it does not contain an active Cloud Datastore or Cloud Firestore database. Please visit http://console.cloud.google.com to create a project or https://console.cloud.google.com/datastore/setup?project=test-app8768 to add a Cloud Datastore or Cloud Firestore database. Note that Cloud Datastore or Cloud Firestore always have an associated App Engine app and this app must not be disabled.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
我的互联网连接非常好。
我的问题
无论如何,我的问题很简单:在使用 Expo 的 React Native App 中,我如何使用 firebase 从数据库中检索文档?
似乎我在滥用语法或缺少一个库(尽管我使用的是允许我使用 update 和 set 的同一个库,所以我假设 getting文档也应该在同一个库中)。非常感谢任何帮助。
【问题讨论】:
标签: firebase react-native google-cloud-firestore expo