0

i am trying to update a subcollection field, which is in an array, but cannot get with where(). wha am i doing wrong?

  async updateDialogueStatus({ state }, data){
    const whoDis =  this.$fire.auth.currentUser
    if (data.dialogue.length > 0) {
      const lastDialogueInArray = data.dialogue.slice(-1)[0];

      const db = this.$fire.firestore;
      db.collection('conversations')
      .doc(data.id)
      .collection('dialogue')
      .where("messageId", "==", lastDialogueInArray.messageId)
      .update({
        status: "read",
        readBy: whoDis.email
      })
    } else {

i am getting this error: Uncaught (in promise) TypeError: db.collection(...).doc(...).collection(...).where(...).update is not a function

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
Teoman Kirac
  • 748
  • 3
  • 8
  • 16
  • not exacty. but i am reading in more detail to possibly infer the answer. thanks for the link. – Teoman Kirac Jan 04 '22 at 20:48
  • Firestore doesn't support so-called update queries, where you send a condition to the database and it updates all matching documents. Instead you will need to execute the query, loop over the results, and update each document in turn - as shown in the answer to the linked question. – Frank van Puffelen Jan 04 '22 at 21:13
  • how can i update a document reference returned from a loop? when i get the correct nested array and then do: .then(snapshots => { snapshots.data().dialogue.forEach(dialogue => { dialogue.update({status: "read"}) }) }) i get "dialogue.update is not a function" – Teoman Kirac Jan 04 '22 at 22:08
  • That'd be `snapshot.ref.update({status: "read"})` iirc. I find it easiest to figure stuff like this out by working from the reference docs: https://firebase.google.com/docs/reference/js/v8/firebase.firestore.DocumentSnapshot – Frank van Puffelen Jan 04 '22 at 22:18
  • thank you so much Frank, will refer to those. – Teoman Kirac Jan 04 '22 at 22:22

0 Answers0