[Vuejs]-I am trying to access a specific row but I am having an error in Vue

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 CollectionReferences.

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
            })
        });
    });
},

Leave a comment