【发布时间】:2018-08-02 17:18:52
【问题描述】:
问题
我正在尝试从查询中检索文档引用。我的代码返回undefined。我可以通过提取documentSnapshot.ref的各个部分来获得路径,但这并不简单。
我想要返回的是一个引用,以后我可以将其用于.update 文档,而无需指定集合并使用documentSnapshot.id
path 属性的文档是 here
我的代码
const db = admin.firestore();
return db.collection('myCollection').get().then(querySnapshot => {
querySnapshot.forEach(documentSnapshot => {
console.log(`documentReference.id = ${documentSnapshot.id}`);
console.log(`documentReference.path = ${documentSnapshot.path}`);
// console.log(`documentReference.ref = ${JSON.stringify(documentSnapshot.ref)}`);
});
});
输出
documentReference.id = Jez7R1GAHiR9nbjS3CQ6
documentReference.path = undefined
documentReference.id = skMmxxUIFXPyVa7Ic7Yp
documentReference.path = undefined
【问题讨论】:
标签: javascript firebase google-cloud-firestore firebase-admin