|
16 | 16 | // end-db-coll |
17 | 17 |
|
18 | 18 | // start-find |
19 | | -/* Creates a query filter by using builders and |
20 | | - retrieves matching documents */ |
| 19 | +// Creates a query filter by using builders and |
| 20 | +// retrieves matching documents |
21 | 21 | $docs = $collection->find(Query::query( |
22 | 22 | feature_type: Query::eq('Wrecks - Visible'), |
23 | 23 | coordinates: Query::near( |
|
29 | 29 | ) |
30 | 30 | )); |
31 | 31 |
|
32 | | -/* Prints matching documents */ |
| 32 | +// Prints matching documents |
33 | 33 | foreach ($docs as $doc) { |
34 | 34 | echo json_encode($doc), PHP_EOL; |
35 | 35 | } |
36 | 36 | // end-find |
37 | 37 |
|
38 | 38 | // start-deleteone |
39 | | -/* Creates a query filter by using builders |
40 | | - and deletes the first matching document */ |
| 39 | +// Creates a query filter by using builders |
| 40 | +// and deletes the first matching document |
41 | 41 | $result = $collection->deleteOne(Query::query( |
42 | 42 | feature_type: Query::regex('nondangerous$', '') |
43 | 43 | )); |
44 | 44 |
|
| 45 | +// Prints number of deleted documents |
45 | 46 | echo 'Deleted documents: ', $result->getDeletedCount(), PHP_EOL; |
46 | 47 | // end-deleteone |
47 | 48 |
|
48 | 49 | // start-updateone |
49 | | -/* Creates a query filter and an update document by |
50 | | - using builders and updates the first matching document */ |
| 50 | +// Creates a query filter and an update document by |
| 51 | +// using builders and updates the first matching document |
51 | 52 | $result = $collection->updateOne( |
52 | 53 | Query::query(watlev: Query::eq('partly submerged at high water')), |
53 | 54 | new Pipeline( |
54 | 55 | Stage::set(year: 1870), |
55 | 56 | ), |
56 | 57 | ); |
57 | 58 |
|
| 59 | +// Prints number of updated documents |
58 | 60 | echo 'Updated documents: ', $result->getModifiedCount(), PHP_EOL; |
59 | 61 | // end-updateone |
60 | 62 |
|
61 | 63 | // start-cs |
62 | | -/* Creates a pipeline to filter for update operations and returns |
63 | | - only specific fields */ |
| 64 | +// Creates a pipeline to filter for update operations and return |
| 65 | +// only specific fields |
64 | 66 | $pipeline = [ |
65 | 67 | Stage::match(operationType: Query::eq('update')), |
66 | 68 | Stage::project(operationType: 1, ns: 1, fullDocument: 1), |
67 | 69 | ]; |
68 | 70 |
|
69 | | -/* Opens the change stream */ |
| 71 | +// Opens the change stream |
70 | 72 | $changeStream = $collection->watch( |
71 | 73 | $pipeline, |
72 | 74 | ['fullDocument' => MongoDB\Operation\Watch::FULL_DOCUMENT_UPDATE_LOOKUP] |
73 | 75 | ); |
74 | 76 |
|
75 | | -/* Prints change events based on the pipeline specifications */ |
| 77 | +// Prints change events based on the pipeline specifications |
76 | 78 | for ($changeStream->rewind(); true; $changeStream->next()) { |
77 | 79 | if (! $changeStream->valid()) { |
78 | 80 | continue; |
|
0 commit comments