【发布时间】:2021-08-13 16:01:50
【问题描述】:
我正在尝试检索 firestore firebase 子集合。
下面这段代码一切正常:
await firestore()
.collection('VILLES')
.doc('9HNkAv99pd1rm9Q3vdwd')
.collection('restaurents')
.get()
.then(querySnapshot => {
querySnapshot.forEach(doc => {
const {image, address, description, title, ratings, contact} =
doc.data();
list.push({
id: doc.id,
image: image,
address: address,
description: description,
title: title,
ratings: ratings,
contact: contact,
});
});
});
setrestaurents(list);
if (loading) {
setloading(false);
}
console.log('restaurents:', restaurents);
} catch (e) {
console.log(e);
}
但问题是我有很多文件都有个人收藏 我如何编写代码以便每个文档都能检索自己的子集合,并且我知道问题出在文档 Id 上
我试过了
await firestore()
.collection('VILLES')
.doc(VILLESId)
.collection('restaurents')
.get()
但我收到此错误
可能的未处理承诺拒绝(id:0):
TypeError: undefined is not an object (evalating '_ref2.VILLESId')
【问题讨论】:
标签: javascript react-native google-cloud-firestore