I am using Firestore and am getting this error whenever I try to call the data method on a document from a query snapshot. Here is my code.
let snapshot: FirebaseFirestore.QuerySnapshot<FirebaseFirestore.DocumentData>;
try {
snapshot = await admin.firestore()
.collection("products")
.where("email", "==", email)
.get();
} catch (error) {
// error code
}
if (snapshot.empty) {
// does not exist
return;
}
const docs: DbSubscription[] = [];
snapshot.forEach(({ data, id }) => {
// this is where error is thrown
docs.push({ ...data(), id } as DbSubscription);
});
I confirmed that the document exists and has data because logging snapshot?.docs[0]?.data() to the console outputs what is expected. However calling the data method above throws the error.
Anyone have a clue why this might be happening? Much appreciated!