-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstep07.php
More file actions
36 lines (32 loc) · 907 Bytes
/
step07.php
File metadata and controls
36 lines (32 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
try {
$mongo = new Mongo(); // default host:port
$db = $mongo->example;
$collection = $db->test;
$collection->drop();
$document = array( '_id' => 'gates',
'name' => 'Gaëtan Voyer-Perrault',
'friends' => array('bernie', 'alvin'),
'followers' => 18,
'contact' => array( 'twitter' => '@gatesvp',
'email' => 'gates@10gen.com')
);
$collection->insert($document);
// update our document
$query = array( '_id' => 'gates' );
$update = array(
'$set' => array('name' => 'GVP',
'contact.website' => 'http://10gen.com/'),
'$inc' => array('followers' => 1),
'$push' => array('friends' => 'antoine'),
'$unset' => array('contact.twitter' => 1)
);
$collection->update($query, $update);
$query = array( '_id' => 'gates');
$result = $collection->findOne($query);
print_r($result);
}
catch(Exception $e) {
print($e->getMessage());
}
?>