Skip to content

Commit 948fc35

Browse files
committed
JM tech review 1
1 parent 5f5266d commit 948fc35

File tree

3 files changed

+34
-39
lines changed

3 files changed

+34
-39
lines changed

source/aggregation.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ The {+library-short+} provides the following APIs to create aggregation
9090
pipelines:
9191

9292
- :ref:`php-aggregation-array-api`: Create aggregation pipelines by
93-
passing arrays that specify the aggregation operators and parameters.
94-
- :ref:`php-aggregation-builder-api`: Create aggregation pipelines by using native
95-
classes and methods to make your application more type-safe and debuggable.
93+
passing arrays that specify the aggregation stages.
94+
- :ref:`php-aggregation-builder-api`: Create aggregation pipelines by
95+
using factory methods to make your application more type-safe and debuggable.
9696

9797
The following sections describe each API and provide examples for
9898
creating aggregation pipelines.
@@ -109,8 +109,8 @@ shown in the following code:
109109
.. code-block:: php
110110

111111
$pipeline = [
112-
['<operator>' => <parameters>],
113-
['<operator>' => <parameters>],
112+
['<stage>' => <parameters>],
113+
['<stage>' => <parameters>],
114114
...
115115
];
116116

@@ -198,7 +198,7 @@ perform the following actions:
198198

199199
1. Create an array to store the pipeline stages.
200200

201-
#. For each stage, call the an operator method from the
201+
#. For each stage, call the a factory method from the
202202
``Stage`` that shares the same name as your desired aggregation
203203
stage. For example, to create an ``$unwind`` stage, call the
204204
``Stage::unwind()`` method.
@@ -213,10 +213,10 @@ aggregation pipelines:
213213
.. code-block:: php
214214

215215
$pipeline = [
216-
Stage::<operator method>(
216+
Stage::<factory method>(
217217
<stage specification>
218218
),
219-
Stage::<operator method>(
219+
Stage::<factory method>(
220220
<stage specification>
221221
),
222222
...

source/includes/aggregation/aggregation.php

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
<?php
22

3-
use MongoDB\BSON\UTCDateTime;
4-
use MongoDB\Builder\Accumulator;
5-
use MongoDB\Builder\Expression;
6-
use MongoDB\Builder\Query;
7-
use MongoDB\Builder\Stage;
8-
use MongoDB\Builder\Type\Sort;
9-
103
require 'vendor/autoload.php';
114

125
$uri = getenv('MONGODB_URI') ?: throw new RuntimeException('Set the MONGODB_URI variable to your Atlas URI that connects to the sample dataset');
@@ -48,27 +41,27 @@
4841

4942
// start-builder-match-group
5043
$pipeline = [
51-
Stage::match(
44+
MongoDB\Builder\Stage::match(
5245
date: [
53-
Query::gte(new UTCDateTime(new DateTimeImmutable('2014-01-01'))),
54-
Query::lt(new UTCDateTime(new DateTimeImmutable('2015-01-01'))),
46+
MongoDB\Builder\Query::gte(new MongoDB\BSON\UTCDateTime(new DateTimeImmutable('2014-01-01'))),
47+
MongoDB\Builder\Query::lt(new MongoDB\BSON\UTCDateTime(new DateTimeImmutable('2015-01-01'))),
5548
],
5649
),
57-
Stage::group(
58-
_id: Expression::dateToString(Expression::dateFieldPath('date'), '%Y-%m-%d'),
59-
totalSaleAmount: Accumulator::sum(
60-
Expression::multiply(
61-
Expression::numberFieldPath('price'),
62-
Expression::numberFieldPath('quantity'),
50+
MongoDB\Builder\Stage::group(
51+
_id: MongoDB\Builder\Expression::dateToString(MongoDB\Builder\Expression::dateFieldPath('date'), '%Y-%m-%d'),
52+
totalSaleAmount: MongoDB\Builder\Accumulator::sum(
53+
MongoDB\Builder\Expression::multiply(
54+
MongoDB\Builder\Expression::numberFieldPath('price'),
55+
MongoDB\Builder\Expression::numberFieldPath('quantity'),
6356
),
6457
),
65-
averageQuantity: Accumulator::avg(
66-
Expression::numberFieldPath('quantity'),
58+
averageQuantity: MongoDB\Builder\Accumulator::avg(
59+
MongoDB\Builder\Expression::numberFieldPath('quantity'),
6760
),
68-
count: Accumulator::sum(1),
61+
count: MongoDB\Builder\Accumulator::sum(1),
6962
),
70-
Stage::sort(
71-
totalSaleAmount: Sort::Desc,
63+
MongoDB\Builder\Stage::sort(
64+
totalSaleAmount: MongoDB\Builder\Type\Sort::Desc,
7265
),
7366
];
7467

@@ -81,14 +74,14 @@
8174

8275
// start-builder-unwind
8376
$pipeline = [
84-
Stage::unwind(Expression::arrayFieldPath('items')),
85-
Stage::unwind(Expression::arrayFieldPath('items.tags')),
86-
Stage::group(
87-
_id: Expression::fieldPath('items.tags'),
88-
totalSalesAmount: Accumulator::sum(
89-
Expression::multiply(
90-
Expression::numberFieldPath('items.price'),
91-
Expression::numberFieldPath('items.quantity'),
77+
MongoDB\Builder\Stage::unwind(MongoDB\Builder\Expression::arrayFieldPath('items')),
78+
MongoDB\Builder\Stage::unwind(MongoDB\Builder\Expression::arrayFieldPath('items.tags')),
79+
MongoDB\Builder\Stage::group(
80+
_id: MongoDB\Builder\Expression::fieldPath('items.tags'),
81+
totalSalesAmount: MongoDB\Builder\Accumulator::sum(
82+
MongoDB\Builder\Expression::multiply(
83+
MongoDB\Builder\Expression::numberFieldPath('items.price'),
84+
MongoDB\Builder\Expression::numberFieldPath('items.quantity'),
9285
),
9386
),
9487
),
@@ -101,9 +94,11 @@
10194
}
10295
// end-builder-unwind
10396

97+
$collection = $client->db->orders;
98+
10499
// start-builder-lookup
105100
$pipeline = [
106-
Stage::lookup(
101+
MongoDB\Builder\Stage::lookup(
107102
from: 'inventory',
108103
localField: 'item',
109104
foreignField: 'sku',

source/whats-new.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The {+library-short+} v1.21 release includes the following features,
3939
improvements, and fixes:
4040

4141
- Introduces the Aggregation Builder, an API to build aggregation
42-
pipelines in a more type-safe and PHP-native way. To learn more and
42+
pipelines in a more type-safe way. To learn more and
4343
view examples, see the :ref:`php-aggregation-builder-api` section of
4444
the Aggregation guide.
4545

0 commit comments

Comments
 (0)