Skip to content

Commit 27fb8da

Browse files
rustagirgithub-actions[bot]
authored andcommitted
DOCSP-47217: pipeline param (#217)
* DOCSP-47217: pipeline param * JT tech review comment (cherry picked from commit b287751)
1 parent 0b8d50e commit 27fb8da

10 files changed

+48
-34
lines changed

source/aggregation.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ shown in the following code:
111111
$pipeline = [
112112
['<stage>' => <parameters>],
113113
['<stage>' => <parameters>],
114-
...
114+
// ...
115115
];
116116

117117
$cursor = $collection->aggregate($pipeline);
@@ -196,7 +196,7 @@ Aggregation Builder
196196
To create an aggregation pipeline by using the Aggregation Builder,
197197
perform the following actions:
198198

199-
1. Create an array to store the pipeline stages.
199+
1. Create a ``MongoDB\Builder\Pipeline`` instance to store the pipeline stages.
200200

201201
#. For each stage, call the a factory method from the
202202
``Stage`` that shares the same name as your desired aggregation
@@ -212,15 +212,15 @@ aggregation pipelines:
212212

213213
.. code-block:: php
214214

215-
$pipeline = [
215+
$pipeline = new Pipeline(
216216
Stage::<factory method>(
217217
<stage specification>
218218
),
219219
Stage::<factory method>(
220220
<stage specification>
221221
),
222-
...
223-
];
222+
// ...
223+
);
224224

225225
$cursor = $collection->aggregate($pipeline);
226226

source/aggregation/atlas-search.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Search queries by using the Aggregation Builder:
6565
To create a ``$search`` stage in your aggregation pipeline, perform the
6666
following actions:
6767

68-
1. Create an array to store the pipeline stages.
68+
1. Create a ``Pipeline`` instance to store the pipeline stages.
6969

7070
#. Call the ``Stage::search()`` method to create the Atlas Search stage.
7171

@@ -77,12 +77,12 @@ queries:
7777

7878
.. code-block:: php
7979

80-
$pipeline = [
80+
$pipeline = new Pipeline(
8181
Stage::search(
8282
/* Atlas Search query specifications
8383
Search::compound(...) */
8484
),
85-
];
85+
);
8686

8787
Atlas Search Query Examples
8888
---------------------------

source/aggregation/vector-search.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Search queries by using the Aggregation Builder:
6666
To create a ``$vectorSearch`` stage in your aggregation pipeline, perform the
6767
following actions:
6868

69-
1. Create an array to store the pipeline stages.
69+
1. Create a ``Pipeline`` instance to store the pipeline stages.
7070

7171
#. Call the ``Stage::vectorSearch()`` method to create the Atlas Vector
7272
Search stage.
@@ -79,13 +79,13 @@ queries:
7979

8080
.. code-block:: php
8181

82-
$pipeline = [
82+
$pipeline = new Pipeline(
8383
Stage::vectorSearch(
8484
/* Atlas Vector Search query specifications
8585
index: '<index name>',
8686
path: '<path to embeddings>', ...*/
8787
),
88-
];
88+
);
8989

9090
You must pass the following parameters to the ``vectorSearch()`` method:
9191

source/includes/aggregation/aggregation.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
// end-array-explain
4141

4242
// start-builder-match-group
43-
$pipeline = [
43+
$pipeline = new MongoDB\Builder\Pipeline(
4444
MongoDB\Builder\Stage::match(
4545
date: [
4646
MongoDB\Builder\Query::gte(new MongoDB\BSON\UTCDateTime(new DateTimeImmutable('2014-01-01'))),
@@ -63,7 +63,7 @@
6363
MongoDB\Builder\Stage::sort(
6464
totalSaleAmount: MongoDB\Builder\Type\Sort::Desc,
6565
),
66-
];
66+
);
6767

6868
$cursor = $collection->aggregate($pipeline);
6969

@@ -73,7 +73,7 @@
7373
// end-builder-match-group
7474

7575
// start-builder-unwind
76-
$pipeline = [
76+
$pipeline = new MongoDB\Builder\Pipeline(
7777
MongoDB\Builder\Stage::unwind(MongoDB\Builder\Expression::arrayFieldPath('items')),
7878
MongoDB\Builder\Stage::unwind(MongoDB\Builder\Expression::arrayFieldPath('items.tags')),
7979
MongoDB\Builder\Stage::group(
@@ -85,7 +85,7 @@
8585
),
8686
),
8787
),
88-
];
88+
);
8989

9090
$cursor = $collection->aggregate($pipeline);
9191

@@ -97,14 +97,14 @@
9797
$collection = $client->db->orders;
9898

9999
// start-builder-lookup
100-
$pipeline = [
100+
$pipeline = new MongoDB\Builder\Pipeline(
101101
MongoDB\Builder\Stage::lookup(
102102
from: 'inventory',
103103
localField: 'item',
104104
foreignField: 'sku',
105105
as: 'inventory_docs',
106106
),
107-
];
107+
);
108108

109109
/* Performs the aggregation on the orders collection */
110110
$cursor = $collection->aggregate($pipeline);

source/includes/aggregation/atlas-search.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
// start-imports
4+
use MongoDB\Builder\Pipeline;
45
use MongoDB\Builder\Search;
56
use MongoDB\Builder\Stage;
67
// end-imports
@@ -34,7 +35,7 @@
3435
echo "\n";
3536

3637
// start-compound-search-query
37-
$pipeline = [
38+
$pipeline = new Pipeline(
3839
Stage::search(
3940
Search::compound(
4041
must: [
@@ -63,7 +64,7 @@
6364
name: 1
6465
),
6566
Stage::limit(3)
66-
];
67+
);
6768

6869
$cursor = $collection->aggregate($pipeline);
6970

@@ -109,7 +110,7 @@
109110
echo "\n";
110111

111112
// start-autocomplete-search-query
112-
$pipeline = [
113+
$pipeline = new Pipeline(
113114
Stage::search(
114115
Search::autocomplete(
115116
query: 'Lucy',
@@ -118,7 +119,7 @@
118119
),
119120
Stage::limit(3),
120121
Stage::project(_id: 0, name: 1),
121-
];
122+
);
122123

123124
$cursor = $collection->aggregate($pipeline);
124125

source/includes/aggregation/vector-search.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
// start-imports
4+
use MongoDB\Builder\Pipeline;
45
use MongoDB\Builder\Stage;
56
// end-imports
67

@@ -42,7 +43,7 @@
4243
echo "\n";
4344

4445
// start-basic-query
45-
$pipeline = [
46+
$pipeline = new Pipeline(
4647
Stage::vectorSearch(
4748
index: 'vector',
4849
path: 'plot_embedding',
@@ -54,7 +55,7 @@
5455
_id: 0,
5556
title: 1,
5657
),
57-
];
58+
);
5859

5960
$cursor = $collection->aggregate($pipeline);
6061

@@ -64,7 +65,7 @@
6465
// end-basic-query
6566

6667
// start-score-query
67-
$pipeline = [
68+
$pipeline = new Pipeline(
6869
Stage::vectorSearch(
6970
index: 'vector',
7071
path: 'plot_embedding',
@@ -77,7 +78,7 @@
7778
title: 1,
7879
score: ['$meta' => 'vectorSearchScore'],
7980
),
80-
];
81+
);
8182

8283
$cursor = $collection->aggregate($pipeline);
8384

source/read/cursor.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ Retrieve All Documents
115115
To retrieve all documents from a cursor, convert the cursor into an array by using
116116
either of the following methods:
117117

118-
- ``MongoDB\\Driver\\Cursor::toArray()``: Call on a ``MongoDB\Driver\Cursor`` object
119-
- ``iterator_to_array()``: Pass a ``MongoDB\Driver\Cursor`` object as a parameter
118+
- :php:`MongoDB\Driver\Cursor::toArray() <mongodb-driver-cursor.toarray>`: Call
119+
on a ``MongoDB\Driver\Cursor`` object
120+
- :php:`iterator_to_array() <function.iterator-to-array>`: Pass a
121+
``MongoDB\Driver\Cursor`` object as a parameter
120122

121123
The following example calls the ``toArray()`` method on a cursor to store its results
122124
in an array:
@@ -187,4 +189,4 @@ API Documentation
187189
~~~~~~~~~~~~~~~~~
188190

189191
To learn more about the ``find()`` method, see the API documentation for
190-
:phpmethod:`MongoDB\Collection::find()`.
192+
:phpmethod:`MongoDB\Collection::find()`.

source/reference/method/MongoDBCollection-aggregate.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ Definition
2020
.. code-block:: php
2121

2222
function aggregate(
23-
array $pipeline,
23+
array|Pipeline $pipeline,
2424
array $options = []
2525
): Traversable
2626

2727
Parameters
2828
----------
2929

30-
``$pipeline`` : array
30+
``$pipeline`` : array|Pipeline
3131
Specifies an :manual:`aggregation pipeline </core/aggregation-pipeline>`
32-
operation.
32+
operation. You can include aggregation stages in a
33+
``MongoDB\Builder\Pipeline`` instance or in an array.
3334

3435
``$options`` : array
3536
An array specifying the desired options.
@@ -186,6 +187,7 @@ group, and sorts the results by name.
186187
See Also
187188
--------
188189

190+
- :ref:`php-aggregation`
189191
- :phpmethod:`MongoDB\Database::aggregate()`
190192
- :manual:`aggregate </reference/command/aggregate>` command reference in the
191193
MongoDB manual

source/reference/method/MongoDBDatabase-aggregate.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,17 @@ Definition
2424
.. code-block:: php
2525

2626
function aggregate(
27-
array $pipeline,
27+
array|Pipeline $pipeline,
2828
array $options = []
2929
): Traversable
3030

3131
Parameters
3232
----------
3333

34-
``$pipeline`` : array
34+
``$pipeline`` : array|Pipeline
3535
Specifies an :manual:`aggregation pipeline </core/aggregation-pipeline>`
36-
operation.
36+
operation. You can include aggregation stages in a
37+
``MongoDB\Builder\Pipeline`` instance or in an array.
3738

3839
``$options`` : array
3940
An array specifying the desired options.
@@ -169,6 +170,7 @@ running command operations.
169170
See Also
170171
--------
171172

173+
- :ref:`php-aggregation`
172174
- :phpmethod:`MongoDB\Collection::aggregate()`
173175
- :manual:`aggregate </reference/command/aggregate>` command reference in the
174176
MongoDB manual

source/whats-new.txt

+6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ and removals:
6464
replaced by these new methods in a future driver release, so consider
6565
changing the usages in your application.
6666

67+
- Modifies the :phpmethod:`MongoDB\Database::aggregate()` and
68+
:phpmethod:`MongoDB\Collection::aggregate()` methods so they can
69+
accept a ``Pipeline`` instance as the ``$pipeline`` parameter. To view
70+
examples that use this construction, see the
71+
:ref:`php-aggregation-builder-api` section of the Aggregation guide.
72+
6773
- Removes deprecated fields in GridFS types.
6874

6975
- The library does not calculate the ``md5`` field when a file is

0 commit comments

Comments
 (0)