简体   繁体   English

如何从firestore查询中只获取一个字段,我正在获取所有字段

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

I can output all the fields in console, but I want to output only 1. I only want to get the ID field but I somehow cannot do it.我可以 output 控制台中的所有字段,但我只想 output 1。我只想获取 ID 字段,但我无法做到。 The following screenshots shows my code and the output.以下屏幕截图显示了我的代码和 output。

Code:代码:

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 in console:控制台中的 Output:

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

Firestore always retrieves the complete document from the server, but you can display just one field with: Firestore 总是从服务器检索完整的文档,但您可以只显示一个字段:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Firebase Firestore 上获取一个字段? - How can I get one field on Firebase Firestore? 从 Firestore 中的一个文档中获取一个字段 - Get one field from one document in Firestore 使用 firestore 仅查询特定字段 - Query only specific field with firestore 如何根据 Cloud Firestore 中的主集合字段和子集合字段查询子集合中的文档? - How to query documents from a sub-collection, based on a main collection's field and a sub-collection's fields in cloud firestore? 我正在尝试从 ReactJS 更新 Firestore 文档中的字段 - I am trying to update a field inside a document in Firestore from ReactJS 如何从Flutter上的Firestore获取collections的列表和一个集合下所有字段的列表? - How to get a list of collections and a list of all fields under a collection from Firestore on Flutter? 我如何从 flutter firestore 中的 querysnapshot 获取单个字段值 - How do i get the single field value from querysnapshot in flutter firestore 从 Firestore 获取字段的 Map - Get a Map of fields from Firestore 我想从 firestore 中的集合中获取多个字段的文档 - I want to get documents for multiple fields from a collection in firestore 从firestore(firebase)获取数据时出现错误。 我正在使用本机反应 - I am getting an error while fetching data from firestore(firebase). I am using react native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM