title: How to set/modify value of a collection field from MongoDB Atlas triggers?
body: <p>I have a MongoDB in Atlas and a collection that has createdAt/lastModifiedAt fields. I would like to set up triggers to automatically handle these fields. The following is my trigger for setting createdAt:</p>
  
  <pre><code>const collection = context.services.get("comand-dev").db("test").collection("ownerDetails");
  const docId = changeEvent.documentKey._id;
  collection;
  collection.update(
    {_id : docId} ,
    { 
      $set : 
       {
         createdAt: Date()
       } 
    }
  );
  
  </code></pre>
  
  <p>This trigger function throws the following error and I don't know what I need to do to have a successfull trigger:</p>
  
  <pre><code>TypeError: 'update' is not a function
  &gt; trace: 
  TypeError: 'update' is not a function
      at exports (function.js:44:3)
      at apply (&lt;native code&gt;)
      at function_wrapper.js:2:3
      at &lt;anonymous&gt;:12:1
  
  </code></pre>