|
3 | 3 | use MongoDB\BSON\UTCDateTime;
|
4 | 4 | use MongoDB\Builder\Accumulator;
|
5 | 5 | use MongoDB\Builder\Expression;
|
6 |
| -use MongoDB\Builder\Pipeline; |
7 | 6 | use MongoDB\Builder\Query;
|
8 | 7 | use MongoDB\Builder\Stage;
|
9 | 8 | use MongoDB\Builder\Type\Sort;
|
|
48 | 47 | // end-array-explain
|
49 | 48 |
|
50 | 49 | // start-builder-match-group
|
51 |
| -$pipeline = new Pipeline( |
| 50 | +$pipeline = [ |
52 | 51 | Stage::match(
|
53 | 52 | date: [
|
54 | 53 | Query::gte(new UTCDateTime(new DateTimeImmutable('2014-01-01'))),
|
|
71 | 70 | Stage::sort(
|
72 | 71 | totalSaleAmount: Sort::Desc,
|
73 | 72 | ),
|
74 |
| -); |
| 73 | +]; |
75 | 74 |
|
76 |
| -$cursor = $collection->aggregate(iterator_to_array($pipeline)); |
| 75 | +$cursor = $collection->aggregate($pipeline); |
77 | 76 |
|
78 | 77 | foreach ($cursor as $doc) {
|
79 | 78 | echo json_encode($doc), PHP_EOL;
|
80 | 79 | }
|
81 | 80 | // end-builder-match-group
|
82 | 81 |
|
83 | 82 | // start-builder-unwind
|
84 |
| -$pipeline = new Pipeline( |
| 83 | +$pipeline = [ |
85 | 84 | Stage::unwind(Expression::arrayFieldPath('items')),
|
86 | 85 | Stage::unwind(Expression::arrayFieldPath('items.tags')),
|
87 | 86 | Stage::group(
|
|
93 | 92 | ),
|
94 | 93 | ),
|
95 | 94 | ),
|
96 |
| -); |
| 95 | +]; |
97 | 96 |
|
98 |
| -$cursor = $collection->aggregate(iterator_to_array($pipeline)); |
| 97 | +$cursor = $collection->aggregate($pipeline); |
99 | 98 |
|
100 | 99 | foreach ($cursor as $doc) {
|
101 | 100 | echo json_encode($doc), PHP_EOL;
|
102 | 101 | }
|
103 | 102 | // end-builder-unwind
|
104 | 103 |
|
105 | 104 | // start-builder-lookup
|
106 |
| -$pipeline = new Pipeline( |
| 105 | +$pipeline = [ |
107 | 106 | Stage::lookup(
|
108 | 107 | from: 'inventory',
|
109 | 108 | localField: 'item',
|
110 | 109 | foreignField: 'sku',
|
111 | 110 | as: 'inventory_docs',
|
112 | 111 | ),
|
113 |
| -); |
| 112 | +]; |
114 | 113 |
|
115 | 114 | /* Perform the aggregation on the orders collection */
|
116 |
| -$cursor = $collection->aggregate(iterator_to_array($pipeline)); |
| 115 | +$cursor = $collection->aggregate($pipeline); |
117 | 116 |
|
118 | 117 | foreach ($cursor as $doc) {
|
119 | 118 | echo json_encode($doc), PHP_EOL;
|
|
0 commit comments