title: Push object into array if the array exists otherwise create the array with object in MongoDB
body: <p>I have collection with a document like this:</p>
  
  <pre><code>{
      _id : "abcd",
      name : "Tom",
      myArray : [
          {
              field1 : "",
              field2 : ""
          }
      ]
  },
  {
      _id : "efgh",
      name : "Jerry"
  }
  </code></pre>
  
  <p>I have a new object for <code>myArray</code>. I want to write a query to update only one document. </p>
  
  <p>If the query matches the document with <code>_id : "abcd"</code>, then push the new object in to <code>myArray</code> field:</p>
  
  <pre><code>{
      _id : "abcd",
      name : "Tom",
      myArray : [
          {
              field1 : "",
              field2 : ""
          },
          {
              // new object
          }
      ]
  }
  </code></pre>
  
  <p>And if the query matches with <code>_id : "efgh"</code> create the field <code>myArray</code> with new object inside it:</p>
  
  <pre><code>{
      _id : "efgh",
      name : "Jerry"
      myArray : [
           {
                // new object
           }
      ]
  }
  </code></pre>
  
  <p>How can I achieve this?</p>