title: MongoDB $set item in array which does not exists with object as element results in object instead of array
body: <p>Updating elements inside an array is explained here:</p>
  
  <p><a href="https://docs.mongodb.com/manual/reference/operator/update/set/#set-elements-in-arrays" rel="nofollow noreferrer">https://docs.mongodb.com/manual/reference/operator/update/set/#set-elements-in-arrays</a></p>
  
  <p>But in the docs seems the case missing where the array does not exists yet in the document. Example:</p>
  
  <p>If have this document:</p>
  
  <pre><code>{
    _id: 'some-id',
    otherprops: 'value'
  }
  </code></pre>
  
  <p>And I want it to become like this:</p>
  
  <pre><code>{
    // ...
    settings: {
      friends: [
        {
          name: 'John Doe',
          age: 28
        }
      ]
    }
    // ...
  }
  </code></pre>
  
  <p>In this situation I dont know if there is already a settings.friends array. So my query looks like this:</p>
  
  <pre><code>{
    $set: {
      'settings.friends.0.name': 'John Doe',
      'settings.friends.0.age': 28
    }
  }
  </code></pre>
  
  <p>However the document results in like this:</p>
  
  <pre><code>{
    // ...
    settings: {
      friends: {
        0: {
          name: 'John Doe',
          age: 28
        }
      }
    }
    // ...
  }
  </code></pre>
  
  <p>Is there a way to force mongodb to create an array instead of an object in my example <strong>but with using dot notations only.</strong></p>