0

I'm trying to update data in a Cloud Firestore document, but I'm getting an error stating the .where() function isn't available on references, even though the documentation says it should be.

Code below:

deleteJob(e){
        //in Firebase, set "active" on job to N
        /**
        * The id of the job to delete will be bound to the element that calls it here
        **/

        let toInactivate = e.currentTarget.attributes[0].value;
        console.log(toInactivate);
        db.collection('jobs').doc().where("job_uuid", "==", toInactivate).update({
          "active": false
        })


} 

Where db is the firestore reference variable.

Why is this not working?

camelCaseCowboy
  • 946
  • 1
  • 10
  • 26

1 Answers1

0

Firestore does not have the concept of update-queries. To update a set of documents, you will have to have a reference to each of those document and call update on each of them individually.

db.collection('jobs').where("job_uuid", "==", toInactivate).get().then(querySnapshot => {
  querySnapshot.forEach(doc => 
    doc.update({
      "active": false
    })
  })
})
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807