(PECL mongo >= 0.8.0)
mongo_update — Updates objects in a database collection
Removes matching objects, changes them to match a new object form, and resaves them to the database. If there are no matching objects and upsert is set, the new object will be inserted into the database.
The database connection to use.
The database and collection name
The object for which to query.
The object to replace matches with.
Whether to insert newobj into the collection if no objects are returned by the query.
If the update was successful.
Example #1 mongo_update() example
This example shows how to update an existing object.
<?php
$query = array("x" => "y");
$newobj = array("x" => "z");
$conn = mongo_connect("localhost", true);
if (!$conn) {
die("Could not connect.");
}
$ok = mongo_update($conn, "foo.bar", $query, $newobj, false);
if( $ok ) {
echo "updated";
}
?>
The above example will output something similar to:
updated