File tree 11 files changed +43
-36
lines changed
11 files changed +43
-36
lines changed Original file line number Diff line number Diff line change @@ -21,7 +21,6 @@ toc_landing_pages = [
21
21
" /reference/class/MongoDBModelCollectionInfo" ,
22
22
" /reference/class/MongoDBModelDatabaseInfo" ,
23
23
" /reference/class/MongoDBModelIndexInfo" ,
24
- " /get-started" ,
25
24
" /connect" ,
26
25
" /read" ,
27
26
" /databases-collections" ,
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 1
1
.. note ::
2
2
3
- If you run into issues on this step , ask for help in the
3
+ If you run into issues in this tutorial , ask for help in the
4
4
:community-forum: `MongoDB Community Forums <tag/php/> `
5
5
or submit feedback by using the :guilabel: `Rate this page `
6
6
tab on the right or bottom right side of this page.
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 @@ -21,16 +21,17 @@ Definition
21
21
.. code-block:: php
22
22
23
23
function aggregate(
24
- array $pipeline,
24
+ array|Pipeline $pipeline,
25
25
array $options = []
26
26
): Traversable
27
27
28
28
Parameters
29
29
----------
30
30
31
- ``$pipeline`` : array
31
+ ``$pipeline`` : array|Pipeline
32
32
Specifies an :manual:`aggregation pipeline </core/aggregation-pipeline>`
33
- operation.
33
+ operation. You can include aggregation stages in a
34
+ ``MongoDB\Builder\Pipeline`` instance or in an array.
34
35
35
36
``$options`` : array
36
37
An array specifying the desired options.
@@ -187,6 +188,7 @@ group, and sorts the results by name.
187
188
See Also
188
189
--------
189
190
191
+ - :ref:`php-aggregation`
190
192
- :phpmethod:`MongoDB\Database::aggregate()`
191
193
- :manual:`aggregate </reference/command/aggregate>` command reference in the
192
194
MongoDB manual
Original file line number Diff line number Diff line change @@ -25,16 +25,17 @@ Definition
25
25
.. code-block:: php
26
26
27
27
function aggregate(
28
- array $pipeline,
28
+ array|Pipeline $pipeline,
29
29
array $options = []
30
30
): Traversable
31
31
32
32
Parameters
33
33
----------
34
34
35
- ``$pipeline`` : array
35
+ ``$pipeline`` : array|Pipeline
36
36
Specifies an :manual:`aggregation pipeline </core/aggregation-pipeline>`
37
- operation.
37
+ operation. You can include aggregation stages in a
38
+ ``MongoDB\Builder\Pipeline`` instance or in an array.
38
39
39
40
``$options`` : array
40
41
An array specifying the desired options.
@@ -170,6 +171,7 @@ running command operations.
170
171
See Also
171
172
--------
172
173
174
+ - :ref:`php-aggregation`
173
175
- :phpmethod:`MongoDB\Collection::aggregate()`
174
176
- :manual:`aggregate </reference/command/aggregate>` command reference in the
175
177
MongoDB manual
You can’t perform that action at this time.
0 commit comments