Manual
PHP Manual

Updates

Updates can be one of the the most complicated operation available with MongoDB. They combine a query with an action, modifying documents that match the criteria. They are also extremely powerful, allowing you to change documents quickly and replace them altogether. They are done in-place (when possible) with little overhead.

Updating Nested Objects

Suppose we wish to change the name of a comment's author in this document:

{ 
    "_id" : ObjectId("4b06c282edb87a281e09dad9"), 
    "content" : "this is a blog post.",
    "comments" : 
    [
        {
            "author" : "Mike",
            "comment" : "I think that blah blah blah...",
        },
        {
            "author" : "John",
            "comment" : "I disagree."
        }
    ]
}

In order to change an inner field, we use $set (so that all of the other fields are not removed!) with the index of comment to change:

<?php

$blog
->update($criteria, array('$set' => array("comments.1" => array("author" => "Jim"))));

?>


Manual
PHP Manual