【发布时间】:2021-05-01 18:13:55
【问题描述】:
我的 Firestore 中有 2 个收藏品。一个叫业主,第二个叫独角兽。 所有者只有一个名称字段,而独角兽具有名称和对所有者的引用。 我想要一个查询返回一个看起来像这样的对象数组
unicorns = { id: 123,
name: Dreamy,
owner: { id: 1
name: John Cane
}
}
我的查询看起来像这样,但缺少一些我无法弄清楚的东西
let unis = [];
db
.collection("unicorns")
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
let uni = {
id: doc.id,
name: doc.data().name,
owner: doc.data().owner,
};
if (uni.owner) {
doc
.data()
.owner.get()
.then((res) => {
uni.owner = {
id: res.id,
name: res.data().name,
};
unis.push(uni);
})
.then(() => {
setUnicorns(unis);
})
.catch((err) => console.error(err));
} else {
unis.push(uni);
}
});
})
当我设置独角兽钩子并尝试映射结果时,我没有得到我需要的所有数据
【问题讨论】:
-
您好@Reem,如果我的回答解决了您的问题,那么您可以通过单击对勾图标接受它,以便其他人知道问题已解决,否则请随时提出更多问题。
标签: firebase react-native google-cloud-firestore react-hooks