[英]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。
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.