'Add field separately to firestore document

The following code creates a firestore collection and adds data to it:

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

I want to create another function which adds a field to the document at a different time. I have the following function but am getting the error "TypeError: collectionRef.update is not a function"

function saveImage(sender_psid,image) {


  let collectionRef = db.collection('users');


  collectionRef.update({IMG:image}).then(res => {
  console.log(`Document updated at ${res.updateTime}`);
});
}


Solution 1:[1]

Flutter Example:

var userDoc = Firestore.instance.collection('users').document('replaceIdHere');
userDoc.updateData({'fieldName':'newValue'});

Solution 2:[2]

According to this documentation, There is a better way

const cityRef = db.collection('cities').doc('BJ');

const res = await cityRef.set({
  capital: true
}, { merge: true });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 RamKr
Solution 2 Caio Vitullo