0
votes

This is my code:

function saveID(sender_psid,complete){
   let data = new Object();
   data.TASK= complete;
   data.ID = sender_psid;
   db.collection('users').add(data);
}

Right now a new document is created every time the field complete is updated. I want to update the value of complete in firestore instead of creating a new document each time.

1

1 Answers

4
votes

If you want to update an existing document, build a DocumentReference that points to the document to update, and use its update() method to indicate which fields should be changed. The documentation goes over this and gives a code sample:

var cityRef = db.collection('cities').doc('DC');

// Set the 'capital' field of the city
var updateSingle = cityRef.update({ capital: true });