Skip to content

DOCSP-47217: pipeline param #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions source/aggregation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ shown in the following code:
$pipeline = [
['<stage>' => <parameters>],
['<stage>' => <parameters>],
...
// ...
];

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

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

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

.. code-block:: php

$pipeline = [
$pipeline = new Pipeline(
Stage::<factory method>(
<stage specification>
),
Stage::<factory method>(
<stage specification>
),
...
];
// ...
);

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

Expand Down
6 changes: 3 additions & 3 deletions source/aggregation/atlas-search.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Search queries by using the Aggregation Builder:
To create a ``$search`` stage in your aggregation pipeline, perform the
following actions:

1. Create an array to store the pipeline stages.
1. Create a ``Pipeline`` instance to store the pipeline stages.

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

Expand All @@ -77,12 +77,12 @@ queries:

.. code-block:: php

$pipeline = [
$pipeline = new Pipeline(
Stage::search(
/* Atlas Search query specifications
Search::compound(...) */
),
];
);

Atlas Search Query Examples
---------------------------
Expand Down
6 changes: 3 additions & 3 deletions source/aggregation/vector-search.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Search queries by using the Aggregation Builder:
To create a ``$vectorSearch`` stage in your aggregation pipeline, perform the
following actions:

1. Create an array to store the pipeline stages.
1. Create a ``Pipeline`` instance to store the pipeline stages.

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

.. code-block:: php

$pipeline = [
$pipeline = new Pipeline(
Stage::vectorSearch(
/* Atlas Vector Search query specifications
index: '<index name>',
path: '<path to embeddings>', ...*/
),
];
);

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

Expand Down
12 changes: 6 additions & 6 deletions source/includes/aggregation/aggregation.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// end-array-explain

// start-builder-match-group
$pipeline = [
$pipeline = new MongoDB\Builder\Pipeline(
MongoDB\Builder\Stage::match(
date: [
MongoDB\Builder\Query::gte(new MongoDB\BSON\UTCDateTime(new DateTimeImmutable('2014-01-01'))),
Expand All @@ -63,7 +63,7 @@
MongoDB\Builder\Stage::sort(
totalSaleAmount: MongoDB\Builder\Type\Sort::Desc,
),
];
);

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

Expand All @@ -73,7 +73,7 @@
// end-builder-match-group

// start-builder-unwind
$pipeline = [
$pipeline = new MongoDB\Builder\Pipeline(
MongoDB\Builder\Stage::unwind(MongoDB\Builder\Expression::arrayFieldPath('items')),
MongoDB\Builder\Stage::unwind(MongoDB\Builder\Expression::arrayFieldPath('items.tags')),
MongoDB\Builder\Stage::group(
Expand All @@ -85,7 +85,7 @@
),
),
),
];
);

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

Expand All @@ -97,14 +97,14 @@
$collection = $client->db->orders;

// start-builder-lookup
$pipeline = [
$pipeline = new MongoDB\Builder\Pipeline(
MongoDB\Builder\Stage::lookup(
from: 'inventory',
localField: 'item',
foreignField: 'sku',
as: 'inventory_docs',
),
];
);

/* Performs the aggregation on the orders collection */
$cursor = $collection->aggregate($pipeline);
Expand Down
9 changes: 5 additions & 4 deletions source/includes/aggregation/atlas-search.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

// start-imports
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Search;
use MongoDB\Builder\Stage;
// end-imports
Expand Down Expand Up @@ -34,7 +35,7 @@
echo "\n";

// start-compound-search-query
$pipeline = [
$pipeline = new Pipeline(
Stage::search(
Search::compound(
must: [
Expand Down Expand Up @@ -63,7 +64,7 @@
name: 1
),
Stage::limit(3)
];
);

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

Expand Down Expand Up @@ -109,7 +110,7 @@
echo "\n";

// start-autocomplete-search-query
$pipeline = [
$pipeline = new Pipeline(
Stage::search(
Search::autocomplete(
query: 'Lucy',
Expand All @@ -118,7 +119,7 @@
),
Stage::limit(3),
Stage::project(_id: 0, name: 1),
];
);

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

Expand Down
9 changes: 5 additions & 4 deletions source/includes/aggregation/vector-search.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

// start-imports
use MongoDB\Builder\Pipeline;
use MongoDB\Builder\Stage;
// end-imports

Expand Down Expand Up @@ -42,7 +43,7 @@
echo "\n";

// start-basic-query
$pipeline = [
$pipeline = new Pipeline(
Stage::vectorSearch(
index: 'vector',
path: 'plot_embedding',
Expand All @@ -54,7 +55,7 @@
_id: 0,
title: 1,
),
];
);

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

Expand All @@ -64,7 +65,7 @@
// end-basic-query

// start-score-query
$pipeline = [
$pipeline = new Pipeline(
Stage::vectorSearch(
index: 'vector',
path: 'plot_embedding',
Expand All @@ -77,7 +78,7 @@
title: 1,
score: ['$meta' => 'vectorSearchScore'],
),
];
);

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

Expand Down
8 changes: 5 additions & 3 deletions source/read/cursor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@ Retrieve All Documents
To retrieve all documents from a cursor, convert the cursor into an array by using
either of the following methods:

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

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

To learn more about the ``find()`` method, see the API documentation for
:phpmethod:`MongoDB\Collection::find()`.
:phpmethod:`MongoDB\Collection::find()`.
8 changes: 5 additions & 3 deletions source/reference/method/MongoDBCollection-aggregate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ Definition
.. code-block:: php

function aggregate(
array $pipeline,
array|Pipeline $pipeline,
array $options = []
): Traversable

Parameters
----------

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

``$options`` : array
An array specifying the desired options.
Expand Down Expand Up @@ -186,6 +187,7 @@ group, and sorts the results by name.
See Also
--------

- :ref:`php-aggregation`
- :phpmethod:`MongoDB\Database::aggregate()`
- :manual:`aggregate </reference/command/aggregate>` command reference in the
MongoDB manual
Expand Down
8 changes: 5 additions & 3 deletions source/reference/method/MongoDBDatabase-aggregate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@ Definition
.. code-block:: php

function aggregate(
array $pipeline,
array|Pipeline $pipeline,
array $options = []
): Traversable

Parameters
----------

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

``$options`` : array
An array specifying the desired options.
Expand Down Expand Up @@ -169,6 +170,7 @@ running command operations.
See Also
--------

- :ref:`php-aggregation`
- :phpmethod:`MongoDB\Collection::aggregate()`
- :manual:`aggregate </reference/command/aggregate>` command reference in the
MongoDB manual
Expand Down
6 changes: 6 additions & 0 deletions source/whats-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ and removals:
replaced by these new methods in a future driver release, so consider
changing the usages in your application.

- Modifies the :phpmethod:`MongoDB\Database::aggregate()` and
:phpmethod:`MongoDB\Collection::aggregate()` methods so they can
accept a ``Pipeline`` instance as the ``$pipeline`` parameter. To view
examples that use this construction, see the
:ref:`php-aggregation-builder-api` section of the Aggregation guide.

- Removes deprecated fields in GridFS types.

- The library does not calculate the ``md5`` field when a file is
Expand Down
Loading