Database Reference
In-Depth Information
j : If set to true , this Boolean option will force the data to be written to the journal before
indicating the update was a success. Defaults to false .
wtimeout : Used to specify how long the server is to wait for receiving acknowledgement
(in milliseconds). Defaults to 10000.
timeout : Used to specify how long (in milliseconds) the client needs to wait for a response
from the database.
Now let's look at a common example that changes Victoria Wood's first name to “Vicky” without using any of the
modifier operators (these will be discussed momentarily):
// Connect to the database
$c = new MongoClient();
// Select the collection 'people' from the database 'contacts'
$collection = $c->contacts->people;
// Specify the search criteria
$criteria = array("Last Name" => "Wood");
// Specify the information to be changed
$update = array(
"First Name" => "Vicky",
"Last Name" => "Wood",
"Address" => array(
"Street" => "50 Ash lane",
"Place" => "Ystradgynlais",
"Postal Code" => "SA9 6XS",
"Country" => "UK"
)
,
"E-Mail" => array(
" vw@example.com " ,
" vw@office.com "
),
"Phone" => "078-8727-8049",
"Age" => 28
);
// Options
$options = array("upsert" => true);
// Perform the update
$collection->update($criteria,$update,$options);
// Show the result
print_r($collection->findOne($criteria));
The resulting output would look like this:
Array (
[_id] => MongoId Object ()
[First Name] => Vicky
[Last Name] => Wood
[Address] => Array (
[Street] => 50 Ash lane
[Place] => Ystradgynlais
Search WWH ::




Custom Search