title: How to push subdocument into an array using MongoDB
body: <p>I am developing an API using Codeigniter and MongoDB.
  I the user document I got an item called following which is an array.
  I need to push a subdocument containing a users fullname and ID into this array.</p>
  
  <p>Everytime I try the subdocument end up being a subarray.</p>
  
  <p>I am using Alex Bilbie's MongoDB library and this is my query:</p>
  
  <pre><code>$this-&gt;mongo_db-&gt;where(array('_id'=&gt;$user_id))-&gt;push('following', array("{id: 'aa', fullname: 'James Bond'}"))-&gt;update('users');
  </code></pre>
  
  <p>I need the results to be like this:</p>
  
  <pre><code>following : [
      { fullname : "James", id : aa},
      { fullname : "Jane", id : bb}
    ]
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>I solved it this way:</p>
  
  <pre><code>$this-&gt;mongo_db-&gt;where(array('_id'=&gt;$user_id))-&gt;push('following', array('fullname'=&gt;'Earl Spencer','id'=&gt;'bb'))-&gt;update('users');
  </code></pre>