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. The following screenshots shows my code and the 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())
));
{id: '864b7TECyqUdd8Ql7f81saSgoOx2', lastName: '******',
address: '******', contactNo: '******', role:
'******', …}
address: "******"
contactNo: "******"
email: "******"
firstName: "******"
id: "864b7TECyqUdd8Ql7f81saSgoOx2"
lastName: "******"
role: "******"
[[Prototype]]: Object
CodePudding user response:
Firestore always retrieves the complete document from the server, but you can display just one field with:
data.forEach(element=>
console.log(element.data().id)
));