Reputation: 81
I'm trying to create a list of UserNames in my SignUp class to only allow creation of a unique displayNames. However when trying to view the displayName of the object as below, in the console I can see displayName when the initial object is mapped, but trying to store it as a variable gives me undefined for the value.
function nameCheck(){
let userList = [];
db.collection("userNames").get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " => ", doc.data()) //I can see the parameter displayName here with //proper value
console.log(doc.displayName) //here it is being logged as undefined
});
console.log(userList); //I can see the array has the right amount of objects, but they are all //undefined
});
I'm sure it's something simple but I can't get it to work at all.
Upvotes: 1
Views: 28
Reputation: 317928
I think you meant to say:
console.log(doc.data().displayName)
The values of the document properties are in the object returned by data()
.
Upvotes: 1