here is my code:
const posts = firestore.collection("posts");
function myFunc() {
posts.get().then((result) => {
result.docs.forEach((post) => {
console.log(post.poster);
})
})
}
When I run this function it logs undefined for each document when inside the actual documents the poster property is set to a string variable.
To access collection/document data from firestore you need to call the function '.data()' when looping through the document results.
I've updated your code below which will console log the string value from the key 'poster' in the data object for each document in your 'posts' collection.
const posts = firestore.collection("posts");
function myFunc() {
posts.get().then((result) => {
result.docs.forEach((post) => {
console.log(post.data().poster);
})
})
}