簡體   English   中英

如何從firestore查詢中只獲取一個字段,我正在獲取所有字段

[英]How to get only one field from firestore query, i am getting all the fields

我可以 output 控制台中的所有字段,但我只想 output 1。我只想獲取 ID 字段,但我無法做到。 以下屏幕截圖顯示了我的代碼和 output。

代碼:

this.afs.collection("accounts",ref=>ref
          .where("email","==", email)) // email of currently logged in
          .get()
          .subscribe(data=>
            data.forEach(element=>
              //console.log(el.data())
              console.log(element.data())
          ));

控制台中的 Output:

{id: '864b7TECyqUdd8Ql7f81saSgoOx2', lastName: '******',
address: '******', contactNo: '******', role: 
'******', …}
address: "******"
contactNo: "******"
email: "******"
firstName: "******"
id: "864b7TECyqUdd8Ql7f81saSgoOx2"
lastName: "******"
role: "******"
[[Prototype]]: Object

Firestore 總是從服務器檢索完整的文檔,但您可以只顯示一個字段:

data.forEach(element=>
  console.log(element.data().id)
));

暫無
暫無

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

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