0๐
โ
You are calling onSnapshot()
on a DocumentReference
: (firestore.collection('donations').doc()
) and therefore there is no forEach()
method for the DocumentSnapshot
(i.e. your snapShotChnaged
object).
One would use forEach()
on the querySnapshot
returned by onSnapshot()
for CollectionReference
s.
You need to do as follows:
firestore
.collection('donations')
.doc(this.$route.params.id)
.onSnapshot(doc => {
const docData = doc.data());
// ....
});
0๐
You are using forEach
method on DocumentSnapshot
which does not have foreEach
method like query snapshot. check the documentation here
if you are planning to iterate through all the items in the donations collection you can change your code as follows.
getAllDonations() {
firestore
.collection('donations')
.onSnapshot((snapShotChnaged) => {
this.donations = []
snapShotChnaged.forEach((donationDoc) => {
this.donations.push({
id: donationDoc.id,
name: donationDoc.data().name,
surname: donationDoc.data().surname,
class: donationDoc.data().class,
amount: donationDoc.data().amount
})
});
});
},
Source:stackexchange.com