Skip to content

Commit 0b38fc5

Browse files
committed
remov Pipeline type
1 parent 30da9a6 commit 0b38fc5

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

source/aggregation.txt

+5-11
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ Aggregation Builder
194194
To create an aggregation pipeline by using the Aggregation Builder,
195195
perform the following actions:
196196

197-
#. Create a ``Pipeline`` class instance to initialize the pipeline
197+
#. Create an array to store the pipeline stages
198198

199-
#. Within the ``Pipeline`` instance, call an operator method from the ``Stage``
199+
#. For each stage, call an operator method from the ``Stage``
200200
builder class to create that type of aggregation stage
201201

202202
#. Within the body of the ``Stage`` method, use methods from other
@@ -208,23 +208,17 @@ aggregation pipelines:
208208

209209
.. code-block:: php
210210

211-
$pipeline = new Pipeline(
211+
$pipeline = [
212212
Stage::<operator method>(
213213
<stage specification>
214214
),
215215
Stage::<operator method>(
216216
<stage specification>
217217
),
218218
...
219-
);
219+
];
220220

221-
$cursor = $collection->aggregate(iterator_to_array($pipeline));
222-
223-
.. note::
224-
225-
The preceding code uses the ``iterator_to_array()`` method to
226-
convert the ``Pipeline`` instance into an array. You must call this method
227-
on your ``Pipeline`` before passing it to the ``aggregate()`` method.
221+
$cursor = $collection->aggregate($pipeline);
228222

229223
The examples in this section are adapted from the {+mdb-server+} manual.
230224
Each example provides a link to the sample data that you can insert into

source/includes/aggregation.php

+9-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use MongoDB\BSON\UTCDateTime;
44
use MongoDB\Builder\Accumulator;
55
use MongoDB\Builder\Expression;
6-
use MongoDB\Builder\Pipeline;
76
use MongoDB\Builder\Query;
87
use MongoDB\Builder\Stage;
98
use MongoDB\Builder\Type\Sort;
@@ -48,7 +47,7 @@
4847
// end-array-explain
4948

5049
// start-builder-match-group
51-
$pipeline = new Pipeline(
50+
$pipeline = [
5251
Stage::match(
5352
date: [
5453
Query::gte(new UTCDateTime(new DateTimeImmutable('2014-01-01'))),
@@ -71,17 +70,17 @@
7170
Stage::sort(
7271
totalSaleAmount: Sort::Desc,
7372
),
74-
);
73+
];
7574

76-
$cursor = $collection->aggregate(iterator_to_array($pipeline));
75+
$cursor = $collection->aggregate($pipeline);
7776

7877
foreach ($cursor as $doc) {
7978
echo json_encode($doc), PHP_EOL;
8079
}
8180
// end-builder-match-group
8281

8382
// start-builder-unwind
84-
$pipeline = new Pipeline(
83+
$pipeline = [
8584
Stage::unwind(Expression::arrayFieldPath('items')),
8685
Stage::unwind(Expression::arrayFieldPath('items.tags')),
8786
Stage::group(
@@ -93,27 +92,27 @@
9392
),
9493
),
9594
),
96-
);
95+
];
9796

98-
$cursor = $collection->aggregate(iterator_to_array($pipeline));
97+
$cursor = $collection->aggregate($pipeline);
9998

10099
foreach ($cursor as $doc) {
101100
echo json_encode($doc), PHP_EOL;
102101
}
103102
// end-builder-unwind
104103

105104
// start-builder-lookup
106-
$pipeline = new Pipeline(
105+
$pipeline = [
107106
Stage::lookup(
108107
from: 'inventory',
109108
localField: 'item',
110109
foreignField: 'sku',
111110
as: 'inventory_docs',
112111
),
113-
);
112+
];
114113

115114
/* Perform the aggregation on the orders collection */
116-
$cursor = $collection->aggregate(iterator_to_array($pipeline));
115+
$cursor = $collection->aggregate($pipeline);
117116

118117
foreach ($cursor as $doc) {
119118
echo json_encode($doc), PHP_EOL;

0 commit comments

Comments
 (0)