title: Save length of array in extra MongoDB field
body: <p>According to <a href="https://stackoverflow.com/a/7811259/5403618">this</a> answer, I am trying to find out the size of an array and save it in the extra field.</p>
  
  <p>I have a collection <code>user_details</code> and the document structure is something like : </p>
  
  <pre><code>{
      user_id : 1,
      likes : [1,2,3,4],
      likes_count : 0
  }
  </code></pre>
  
  <p>The query I'm using is as follows : </p>
  
  <pre><code>db.user_details.update({user_id : 1},{$set:{ likes_count : this.likes.length }})
  </code></pre>
  
  <p>BUT, it throws error that </p>
  
  <pre><code>"message" : "Cannot read property 'length' of undefined"
  </code></pre>
  
  <p>How do I save the length of an array in extra field?</p>
  
  <p>PS: I'm using MongoDB 3.4 </p>