-
Notifications
You must be signed in to change notification settings - Fork 0
/
step10.php
40 lines (32 loc) · 928 Bytes
/
step10.php
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
37
38
39
40
<?php
try {
$mongo = new Mongo(); // default host:port
$db = $mongo->example;
$collection = $db->test;
$collection->drop();
$document = array(
'normal' => array('first','second'),
'crazy' => array("0" => 'first', '1' => 'second'),
'arrayObj' => new ArrayObject(array('first', 'second')),
'object' => array('1' => 'first', '2' => 'second')
);
$collection->insert($document);
$collection->update(array(),
array('$push' => array('crazy' => 'third'))
); // works
$collection->update(array(),
array('$push' => array('normal' => 'third'))
); // works
$collection->update(array(),
array('$push' => array('object' => 'third'))
); // works
$collection->update(array(),
array('$push' => array('arrayObj' => 'third'))
); // works
$results = $collection->find();
foreach($results as $r) { print_r($r); }
}
catch(Exception $e) {
print($e->getMessage());
}
?>