0

I'm trying to read a movie object that's being pulled from a firebase firestore. All the data seems to be entered correctly. Below is a code snippet where I pull the movies and am just trying to reference and log the values so I can see what they are.

const savedMovies = await getDocs(collection(db,"users/"+currentUserID+"/savedmovies"));
savedMovies.forEach((doc) => {
  console.log(doc.id, " => ", doc.data());
  console.log(doc.Title);
  console.log(doc.data().Title);
  console.log("movie is "+doc.movie.Title);
  console.log(movie.Title);
});

doc.id and doc.data() return what I'm expecting but I can't seem to reference the specific values in these entries. The bottom 4 console.log's either error or return undefined. Below is a photo of what doc.data() shows as in the console.

Image snip from the console for doc.data()

Can anyone explain to me what I'm doing wrong here? Apologies if this is a dumb question and thanks for reading!

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
Dolesy
  • 13
  • 2
  • 1
    `doc.data().movie.Title` seems to be what you're after. I'd recommend only calling `doc.data()` once and saving it to a variable, eg `const { movie } = doc.data(); console.log(movie.Title)` – Phil Nov 04 '21 at 00:52
  • That's exactly it! Thanks a bunch for your time Phil! – Dolesy Nov 04 '21 at 02:03

0 Answers0