【发布时间】:2019-04-11 15:38:42
【问题描述】:
我有这个结构:
- collection(A) // there is two collections in the Firestore in the top.
// But I only wrote one the collection because it gets longer
- doc(918409234)
-collection(B)
- doc(918409234)
object is stored here
- doc(213123133)
object is stored here
- doc(332222212)
object is stored here
- doc(029299292)
object is stored here
- doc(434352342)
object is stored here
- doc(341234123)
-collection(B)
- doc(918409234)
- doc(213123133)
- doc(332222212)
- doc(029299292)
- doc(434352342)
- doc(341234123)
-collection(B)
- doc(918409234)
- doc(213123133)
- doc(332222212)
- doc(029299292)
- doc(434352342)
所以我想检索集合 B 下的节点,但它似乎不起作用。我的代码有什么问题?
何时发布:
function send() {
let path = db.collection(A).doc(randomnumber).
return path.collection(B).doc(randomnumber).set(object);
}
何时获取:
function fetch() {
return db.collection(A).get().then(value => {
value.forEach((doc => {
console.log(doc.id, '=>', doc.data());
}));
return value;
}).catch(err => {
console.log('error found' + err)
return err;
})
}
let snapshot = await firestore.fetch();
console.log('Snapshot: ' + snapshot); // prints [Object, Object]
snapshot.forEach(child => {
let query = child.data();
console.log('Each data: ' + query.B); // not printed in the console
});
但我无法获得第一批文件。所以我不能去下一步获取下一个集合(在这种情况下是集合 B)。调用 fetch 方法但仅打印为 [Object, Object]。这段代码有什么问题?我希望在上面的示例中获取三个节点。我做错了吗?我想获取所有分配有随机数的文档
更新
这样问题就解决了。您无法访问嵌套集合(希望从现在开始)。
【问题讨论】:
标签: node.js database google-cloud-firestore google-cloud-functions