簡體   English   中英

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' 的子級方法示例插入

 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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM