如何在Google Firestore中按ID获取文档?是否有get()
方法可用?我已经搜索了,但没有找到适合我的正确答案:(
更新:对我来说this.itemscollection.doc(id).get()
没有起作用。
如何在Google Firestore中按ID获取文档?是否有get()
方法可用?我已经搜索了,但没有找到适合我的正确答案:(
更新:对我来说this.itemscollection.doc(id).get()
没有起作用。
尝试这段代码
this.itemscollection.doc(id).ref.get().then(function(doc) {
if (doc.exists) {
console.log("Document data:", doc.data());
} else {
console.log("No such document!");
}
}).catch(function(error) {
console.log("Error getting document:", error);
});
在使用 angularFire2 包与 firestore 进行开发时,成功的关键在于要知道所有官方文档中操作单个文档(如 'get'、'set'、'update') 的 firestore 方法都是 'ref' 方法的子方法。
firestore - this.itemscollection.doc(id).get()
angularfirestore2 - this.itemscollection.doc(id).ref.get()
-------------------------------------
firestore - this.itemscollection.doc(id).set()
angularfirestore2 - this.itemscollection.doc(id).ref.set()
.ref
是不必要的。 - Shanqing Cai