Firestore 在 angular 2 上按 ID 获取文档
Firestore get document by id on angular 2
如何在 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);
});
成功使用 angular 2(当使用包 angularFire2 时)与 firestore 的关键是要知道他们官方文档中所有操作单个文档的 firestore 方法,如 'get' 'set' 'update' 是 'ref' 方法的子方法
示例 insted
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()
如何在 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);
});
成功使用 angular 2(当使用包 angularFire2 时)与 firestore 的关键是要知道他们官方文档中所有操作单个文档的 firestore 方法,如 'get' 'set' 'update' 是 'ref' 方法的子方法 示例 insted
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()