Update mongoDB document depending on existing fields


I’m updating a document in my collection using the validated-method package (irrelevant for this though).

Before actually calling the myCollection.update(id, { ... }) function, I’d like to access the fields in in that particular document.


if (myCollection(id).myBooleanField == true) 
   myCollection.update(id, { ... }) }

It seems trivial, but I’m not sure how to do this server side?


Did you try just fetching the document?

var document = myCollection.findOne(id);
if (document && document.myBooleanField == true) {
  myCollection.update(id, {...});