Home > front end >  update subcollection field in firestore
update subcollection field in firestore

Time:01-05

i have a firestore collection and want to update a couple fields in it's subcollection, which is in the form of an array. I cannot manage to do this. the data parameter gets me exactly what I want, and then i slice it to get the last array in subcollection. Have broken it down to collection('').doc('').collection(''), as well, with no luck. Thank you for any help!

async updateDialogueStatus({ state }, data){
    const whoDis =  this.$fire.auth.currentUser
    if (data.dialogue.length > 0) {
      const lastDialogueInArray = data.dialogue.slice(-1)[0];
      this.$fire.firestore.collection('conversations/'   data.id   'dialogue/'   lastDialogueInArray.messageId).update({
           status: "read",
           readBy: whoDis.email
      })
    } else {}

i get this error: "Uncaught (in promise) TypeError: _this2.$fire.firestore.collection(...).update is not a function"

CodePudding user response:

You're constructing a path to the document to update, but then call this.$fire.firestore.collection. Call .doc to get the correct object, on which you can call update.

//                              
  •  Tags:  
  • Related