kobo
kobo

Reputation: 31

Unable to get document data in firestore

I'm trying to access data from a firestore document, but I'm getting an error message that exercise.data() is not a function. I don't understand how the exercisesToAdd array is an array of documents, but I can't use .data() to get the contents of the items? How else would I go about getting the data from those documents?

I know the exercisesToAdd array is actually being filled with documents because I see them in the database when I send the array. Seems straight-forward but I must be missing something.

chosenExercises.forEach((exercise) => {
    exercisesToAdd.push(doc(db, 'Users/' + auth.currentUser.uid + '/Exercises/' + exercise));
});

exercisesToAdd.forEach((exercise) => {
    console.log(exercise.data());
});

Upvotes: 1

Views: 589

Answers (1)

Andrés
Andrés

Reputation: 515

As @Doug Stevenson stated in his comment:

Your code hasn't actually performed any queries, so there is no document data available. Please review the documentation and use get() to execute each document query first before calling data() on anything. All doc() does is create a DocumentReference, which doesn't contain any data.

Upvotes: 1

Related Questions