title: PHP/MongoDB: update a value in an array
body: <p>I have the following mongodb object:</p>
  
  <pre><code>{
     "_id": ObjectId("4d0b9c7a8b012fe287547157"),
     "messages": {
       "0": {
         "toUname": "Eamorr3",
         "fromUname": "Eamorr2",
         "time": 1292606586,
         "id": "ABCDZZZ",
         "subject": "asdf",
         "message": "asdf",
         "read": 0   //I want to change this to 1!
      },
      "1": {
         "toUname": "Eamorr1",
         "fromUname": "Eamorr3",
         "time": 1292606586,
         "id": "EFGHZZZ",
         "subject": "asdf2",
         "message": "asdf2",
         "read": 0
      }
    },
     "uname": "Eamorr3"
  }
  </code></pre>
  
  <p>How do I set "read" to 1 where id=ABCDZZZZ? I'm using PHP.</p>
  
  <p>I've tried the following command:</p>
  
  <pre><code>$driverInboxes-&gt;update(array('uname'=&gt;$uname),array('$set'=&gt;array('messages'=&gt;array('id'=&gt;$id,'read'=&gt;'1'))));
  </code></pre>
  
  <p>But when I do this, overwriting occurs and I get: </p>
  
  <pre><code>{
     "_id": ObjectId("4d0b9c7a8b012fe287547157"),
     "messages": {
       "id": "j7zwr2hzx14d3sucmvp5",
       "read": "1"
    },
     "uname": "Eamorr3"
  }
  </code></pre>
  
  <p>I'm totally stuck. Any help much appreciated.</p>
  
  <p>Do I need to pull the entire array element, modify and and push it back in again?</p>
  
  <p>Many thanks in advance,</p>