|
33 | 33 | $result = $collection->insertOne($bobby);
|
34 | 34 | printf("Inserted: %s (out of expected 1)\n", $result->getNumInserted());
|
35 | 35 |
|
36 |
| - $result = $collection->find(array("nick" => "bjori"), array("projection" => array("name" => 1))); |
37 |
| - echo "Searching for nick => bjori, should have only one result:\n"; |
38 |
| - foreach($result as $document) { |
39 |
| - var_dump($document); |
40 |
| - } |
| 36 | + $count = $collection->count(array("nick" => "bjori")); |
| 37 | + printf("Searching for nick => bjori, should have only one result: %d\n", $count); |
41 | 38 |
|
42 |
| - $result = $collection->deleteOne($document); |
43 |
| - printf("Deleted: %s (out of expected 1)\n", $result->getNumRemoved()); |
44 | 39 | $result = $collection->updateOne(
|
45 | 40 | array("citizen" => "USA"),
|
46 | 41 | array('$set' => array("citizen" => "Iceland"))
|
|
52 | 47 | foreach($result as $document) {
|
53 | 48 | var_dump($document);
|
54 | 49 | }
|
55 |
| - $result = $collection->deleteOne($document); |
56 |
| - printf("Deleted: %d (out of expected 1)\n", $result->getNumRemoved()); |
57 |
| - |
58 | 50 | } catch(Exception $e) {
|
59 | 51 | echo $e->getMessage(), "\n";
|
60 | 52 | exit;
|
61 | 53 | }
|
62 | 54 |
|
63 | 55 | try {
|
64 |
| - /* These two were removed earlier */ |
65 |
| - $result = $collection->insertOne($hannes); |
66 |
| - printf("Inserted: %s (out of expected 1)\n", $result->getNumInserted()); |
67 |
| - $result = $collection->insertOne($hayley); |
68 |
| - printf("Inserted: %s (out of expected 1)\n", $result->getNumInserted()); |
69 |
| - |
70 | 56 | $result = $collection->find();
|
71 |
| - echo "Find all docs, should be 3, verify 2x USA citizen, 1 Icelandic\n"; |
| 57 | + echo "Find all docs, should be 3, verify 1x USA citizen, 2x Icelandic\n"; |
72 | 58 | foreach($result as $document) {
|
73 | 59 | var_dump($document);
|
74 | 60 | }
|
75 | 61 |
|
76 | 62 | $result = $collection->updateMany(
|
77 |
| - array("citizen" => "USA"), |
78 |
| - array('$set' => array("citizen" => "Iceland")) |
| 63 | + array("citizen" => "Iceland"), |
| 64 | + array('$set' => array("viking" => true)) |
79 | 65 | );
|
80 | 66 |
|
81 |
| - printf("Updated: %d (out of expected 2), verify everyone is Icelandic\n", $result->getNumModified()); |
| 67 | + printf("Updated: %d (out of expected 2), verify Icelandic people are vikings\n", $result->getNumModified()); |
82 | 68 | $result = $collection->find();
|
83 | 69 | foreach($result as $document) {
|
84 | 70 | var_dump($document);
|
|
93 | 79 | var_dump($document);
|
94 | 80 | }
|
95 | 81 |
|
| 82 | + $result = $collection->deleteOne($document); |
| 83 | + printf("Deleted: %d (out of expected 1)\n", $result->getNumRemoved()); |
| 84 | + |
96 | 85 | $result = $collection->deleteMany(array("citizen" => "Iceland"));
|
97 |
| - printf("Deleted: %d (out of expected 3)\n", $result->getNumRemoved()); |
| 86 | + printf("Deleted: %d (out of expected 2)\n", $result->getNumRemoved()); |
98 | 87 | } catch(Exception $e) {
|
99 | 88 | echo $e->getMessage(), "\n";
|
100 | 89 | exit;
|
|
0 commit comments