【问题标题】:Firestore Collection Doesn't retrieve expected outputFirestore 集合未检索到预期的输出
【发布时间】:2021-06-05 16:54:18
【问题描述】:
我有一个 react native 函数来获取所有集合文档,如下所示
export const fetchAuctionItems = () => {
return firestore().collection('items').get();
};
当我访问上述函数时,响应没有得到任何文档,而是我正在关注
谁能帮我解决我的问题,谢谢
【问题讨论】:
标签:
firebase
react-native
google-cloud-firestore
【解决方案1】:
collection.get() 返回一个 QuerySnapshot 这就是您看到的数据。您需要从 QuerySnapshot 请求数据,例如。
export const fetchAuctionItems = () => {
return firestore().collection('items')
.get()
.then(querySnapshot => querySnapshot
.docs
.map(d => ({
id: d.id,
...d.data(),
});
};
阅读更多关于 QuerySnapshot here