title: MongoDB $set not updating record
body: <p>I'm experimenting with MongoDB using the PHP PECL extension, however I'm having difficulty getting a certain update query to work. I have searched around on SO for answers with little luck.</p>
  
  <p>I have created a basic collection:</p>
  
  <pre><code>$m = new Mongo;
  $collection = $m-&gt;testdb-&gt;testcollection;
  
  $collection-&gt;insert(array(
      0, 1, 1, 2, 3, 5
  ));
  </code></pre>
  
  <p>Using <code>findOne</code> and <code>var_dump</code> the record appears as follows:</p>
  
  <pre><code>array
    '_id' =&gt; 
      object(MongoId)[6]
        public '$id' =&gt; string '4f3bde65a1f7a0315b000000' (length=24)
    0 =&gt; int 0
    1 =&gt; int 1
    2 =&gt; int 1
    3 =&gt; int 2
    4 =&gt; int 3
    5 =&gt; int 5
  </code></pre>
  
  <p>The problem comes when I want to update using <code>$set</code>. I am basing my query on the mapping shown towards the bottom of the <a href="http://www.php.net/manual/en/mongo.sqltomongo.php" rel="noreferrer">SQL to Mongo Cheat Sheet</a> in the PHP manual</p>
  
  <p>Here I want to update field <code>0</code> to value <code>100</code></p>
  
  <pre><code>$obj = $collection-&gt;findOne();
  
  $collection-&gt;update(
      array('_id' =&gt; $obj['_id']),
      array('$set' =&gt; array(0 =&gt; 100))
  );
  </code></pre>
  
  <p>Re-fetching the record shows that it <strong>remains unchanged</strong>. </p>
  
  <p>I did wonder if I was doing something wrong with the <code>_id</code>, however the following update query <strong>does</strong> work, albeit replacing the entire record with a new value, not simply updating the one field.</p>
  
  <pre><code>$collection-&gt;update(
      array('_id' =&gt; $obj['_id']),
      array(0 =&gt; 100)
  );
  </code></pre>
  
  <p>Object dump:</p>
  
  <pre><code>array
    '_id' =&gt; 
      object(MongoId)[7]
        public '$id' =&gt; string '4f3bde65a1f7a0315b000000' (length=24)
    0 =&gt; int 100
  </code></pre>
  
  <p>Can someone please point out what I am doing wrong, and how to properly use <code>$set</code>. I'm sure it's obvious and I just need a second pair of eyes on it.</p>
  
  <p>Many thanks.</p>