【发布时间】:2020-02-15 19:06:23
【问题描述】:
尝试从 react-native 项目中的 firebase 的 Firestore 的根级集合内的文档中读取所有子集合。不太确定要遵循哪个文档(网络不能做getCollections() /node?)。 Firebase 已导入,我已成功从 firestore 检索其他数据,但我从未能够读取子集合数据。这没有使用库 react-native-firebase (尽管我已经尝试过 react-native-firebase 并且它也没有记录解决方案)无论如何,我已经尝试过:
componentDidMount() {
firebase
.firestore()
.collection('users')
.doc(this.props.user.uid)
.getCollections('conversations')
.then(collections => {
collections.forEach(collection => {
alert(collection.id)
})
})
}
以上返回'_firebase.default.firestore().collection("users").doc(this.props.user.uid).getCollections' is undefined
也试过了:
componentDidMount() {
firebase
.firestore()
.collection("users")
.doc(this.props.user.uid)
.collection("conversations")
.get()
.then(collections => {
collections.forEach(collection => {
alert(JSON.stringify(collection)); //collection.id is can be read here
});
});
在上面,可以读取collection id,但是如何读取文档字段呢?以上给了我循环结构错误。
alert(collection.data()) 给我[object Object]
alert(JSON.stringify(collection.data()) 给我循环结构错误
这里是火库:
实际应用将填充给定用户的所有对话,然后填充给定对话的所有消息。 如何在 react-native 项目中从 Firestore 的所有子集合中读取数据?
【问题讨论】:
标签: firebase react-native google-cloud-firestore react-native-firebase