File tree 10 files changed +48
-34
lines changed
10 files changed +48
-34
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,7 @@ shown in the following code:
111
111
$pipeline = [
112
112
['<stage>' => <parameters>],
113
113
['<stage>' => <parameters>],
114
- ...
114
+ // ...
115
115
];
116
116
117
117
$cursor = $collection->aggregate($pipeline);
@@ -196,7 +196,7 @@ Aggregation Builder
196
196
To create an aggregation pipeline by using the Aggregation Builder,
197
197
perform the following actions:
198
198
199
- 1. Create an array to store the pipeline stages.
199
+ 1. Create a ``MongoDB\Builder\Pipeline`` instance to store the pipeline stages.
200
200
201
201
#. For each stage, call the a factory method from the
202
202
``Stage`` that shares the same name as your desired aggregation
@@ -212,15 +212,15 @@ aggregation pipelines:
212
212
213
213
.. code-block:: php
214
214
215
- $pipeline = [
215
+ $pipeline = new Pipeline(
216
216
Stage::<factory method>(
217
217
<stage specification>
218
218
),
219
219
Stage::<factory method>(
220
220
<stage specification>
221
221
),
222
- ...
223
- ] ;
222
+ // ...
223
+ ) ;
224
224
225
225
$cursor = $collection->aggregate($pipeline);
226
226
Original file line number Diff line number Diff line change @@ -65,7 +65,7 @@ Search queries by using the Aggregation Builder:
65
65
To create a ``$search`` stage in your aggregation pipeline, perform the
66
66
following actions:
67
67
68
- 1. Create an array to store the pipeline stages.
68
+ 1. Create a ``Pipeline`` instance to store the pipeline stages.
69
69
70
70
#. Call the ``Stage::search()`` method to create the Atlas Search stage.
71
71
@@ -77,12 +77,12 @@ queries:
77
77
78
78
.. code-block:: php
79
79
80
- $pipeline = [
80
+ $pipeline = new Pipeline(
81
81
Stage::search(
82
82
/* Atlas Search query specifications
83
83
Search::compound(...) */
84
84
),
85
- ] ;
85
+ ) ;
86
86
87
87
Atlas Search Query Examples
88
88
---------------------------
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ Search queries by using the Aggregation Builder:
66
66
To create a ``$vectorSearch`` stage in your aggregation pipeline, perform the
67
67
following actions:
68
68
69
- 1. Create an array to store the pipeline stages.
69
+ 1. Create a ``Pipeline`` instance to store the pipeline stages.
70
70
71
71
#. Call the ``Stage::vectorSearch()`` method to create the Atlas Vector
72
72
Search stage.
@@ -79,13 +79,13 @@ queries:
79
79
80
80
.. code-block:: php
81
81
82
- $pipeline = [
82
+ $pipeline = new Pipeline(
83
83
Stage::vectorSearch(
84
84
/* Atlas Vector Search query specifications
85
85
index: '<index name>',
86
86
path: '<path to embeddings>', ...*/
87
87
),
88
- ] ;
88
+ ) ;
89
89
90
90
You must pass the following parameters to the ``vectorSearch()`` method:
91
91
Original file line number Diff line number Diff line change 40
40
// end-array-explain
41
41
42
42
// start-builder-match-group
43
- $ pipeline = [
43
+ $ pipeline = new MongoDB \ Builder \ Pipeline (
44
44
MongoDB \Builder \Stage::match (
45
45
date: [
46
46
MongoDB \Builder \Query::gte (new MongoDB \BSON \UTCDateTime (new DateTimeImmutable ('2014-01-01 ' ))),
63
63
MongoDB \Builder \Stage::sort (
64
64
totalSaleAmount: MongoDB \Builder \Type \Sort::Desc,
65
65
),
66
- ] ;
66
+ ) ;
67
67
68
68
$ cursor = $ collection ->aggregate ($ pipeline );
69
69
73
73
// end-builder-match-group
74
74
75
75
// start-builder-unwind
76
- $ pipeline = [
76
+ $ pipeline = new MongoDB \ Builder \ Pipeline (
77
77
MongoDB \Builder \Stage::unwind (MongoDB \Builder \Expression::arrayFieldPath ('items ' )),
78
78
MongoDB \Builder \Stage::unwind (MongoDB \Builder \Expression::arrayFieldPath ('items.tags ' )),
79
79
MongoDB \Builder \Stage::group (
85
85
),
86
86
),
87
87
),
88
- ] ;
88
+ ) ;
89
89
90
90
$ cursor = $ collection ->aggregate ($ pipeline );
91
91
97
97
$ collection = $ client ->db ->orders ;
98
98
99
99
// start-builder-lookup
100
- $ pipeline = [
100
+ $ pipeline = new MongoDB \ Builder \ Pipeline (
101
101
MongoDB \Builder \Stage::lookup (
102
102
from: 'inventory ' ,
103
103
localField: 'item ' ,
104
104
foreignField: 'sku ' ,
105
105
as: 'inventory_docs ' ,
106
106
),
107
- ] ;
107
+ ) ;
108
108
109
109
/* Performs the aggregation on the orders collection */
110
110
$ cursor = $ collection ->aggregate ($ pipeline );
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
3
// start-imports
4
+ use MongoDB \Builder \Pipeline ;
4
5
use MongoDB \Builder \Search ;
5
6
use MongoDB \Builder \Stage ;
6
7
// end-imports
34
35
echo "\n" ;
35
36
36
37
// start-compound-search-query
37
- $ pipeline = [
38
+ $ pipeline = new Pipeline (
38
39
Stage::search (
39
40
Search::compound (
40
41
must: [
63
64
name: 1
64
65
),
65
66
Stage::limit (3 )
66
- ] ;
67
+ ) ;
67
68
68
69
$ cursor = $ collection ->aggregate ($ pipeline );
69
70
109
110
echo "\n" ;
110
111
111
112
// start-autocomplete-search-query
112
- $ pipeline = [
113
+ $ pipeline = new Pipeline (
113
114
Stage::search (
114
115
Search::autocomplete (
115
116
query: 'Lucy ' ,
118
119
),
119
120
Stage::limit (3 ),
120
121
Stage::project (_id: 0 , name: 1 ),
121
- ] ;
122
+ ) ;
122
123
123
124
$ cursor = $ collection ->aggregate ($ pipeline );
124
125
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
3
// start-imports
4
+ use MongoDB \Builder \Pipeline ;
4
5
use MongoDB \Builder \Stage ;
5
6
// end-imports
6
7
42
43
echo "\n" ;
43
44
44
45
// start-basic-query
45
- $ pipeline = [
46
+ $ pipeline = new Pipeline (
46
47
Stage::vectorSearch (
47
48
index: 'vector ' ,
48
49
path: 'plot_embedding ' ,
54
55
_id: 0 ,
55
56
title: 1 ,
56
57
),
57
- ] ;
58
+ ) ;
58
59
59
60
$ cursor = $ collection ->aggregate ($ pipeline );
60
61
64
65
// end-basic-query
65
66
66
67
// start-score-query
67
- $ pipeline = [
68
+ $ pipeline = new Pipeline (
68
69
Stage::vectorSearch (
69
70
index: 'vector ' ,
70
71
path: 'plot_embedding ' ,
77
78
title: 1 ,
78
79
score: ['$meta ' => 'vectorSearchScore ' ],
79
80
),
80
- ] ;
81
+ ) ;
81
82
82
83
$ cursor = $ collection ->aggregate ($ pipeline );
83
84
Original file line number Diff line number Diff line change @@ -115,8 +115,10 @@ Retrieve All Documents
115
115
To retrieve all documents from a cursor, convert the cursor into an array by using
116
116
either of the following methods:
117
117
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
120
122
121
123
The following example calls the ``toArray()`` method on a cursor to store its results
122
124
in an array:
@@ -187,4 +189,4 @@ API Documentation
187
189
~~~~~~~~~~~~~~~~~
188
190
189
191
To learn more about the ``find()`` method, see the API documentation for
190
- :phpmethod:`MongoDB\Collection::find()`.
192
+ :phpmethod:`MongoDB\Collection::find()`.
Original file line number Diff line number Diff line change @@ -20,16 +20,17 @@ Definition
20
20
.. code-block:: php
21
21
22
22
function aggregate(
23
- array $pipeline,
23
+ array|Pipeline $pipeline,
24
24
array $options = []
25
25
): Traversable
26
26
27
27
Parameters
28
28
----------
29
29
30
- ``$pipeline`` : array
30
+ ``$pipeline`` : array|Pipeline
31
31
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.
33
34
34
35
``$options`` : array
35
36
An array specifying the desired options.
@@ -186,6 +187,7 @@ group, and sorts the results by name.
186
187
See Also
187
188
--------
188
189
190
+ - :ref:`php-aggregation`
189
191
- :phpmethod:`MongoDB\Database::aggregate()`
190
192
- :manual:`aggregate </reference/command/aggregate>` command reference in the
191
193
MongoDB manual
Original file line number Diff line number Diff line change @@ -24,16 +24,17 @@ Definition
24
24
.. code-block:: php
25
25
26
26
function aggregate(
27
- array $pipeline,
27
+ array|Pipeline $pipeline,
28
28
array $options = []
29
29
): Traversable
30
30
31
31
Parameters
32
32
----------
33
33
34
- ``$pipeline`` : array
34
+ ``$pipeline`` : array|Pipeline
35
35
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.
37
38
38
39
``$options`` : array
39
40
An array specifying the desired options.
@@ -169,6 +170,7 @@ running command operations.
169
170
See Also
170
171
--------
171
172
173
+ - :ref:`php-aggregation`
172
174
- :phpmethod:`MongoDB\Collection::aggregate()`
173
175
- :manual:`aggregate </reference/command/aggregate>` command reference in the
174
176
MongoDB manual
Original file line number Diff line number Diff line change @@ -64,6 +64,12 @@ and removals:
64
64
replaced by these new methods in a future driver release, so consider
65
65
changing the usages in your application.
66
66
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
+
67
73
- Removes deprecated fields in GridFS types.
68
74
69
75
- The library does not calculate the ``md5`` field when a file is
You can’t perform that action at this time.
0 commit comments