Skip to content

Commit bc8dc34

Browse files
committed
LM PR fixes 1
1 parent 52d6609 commit bc8dc34

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

source/builders.txt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@ Overview
2323
In this guide, you can learn about the **builder classes**
2424
that the {+library-short+} provides to create types used in your
2525
operations. You can use the builder classes and factory methods from the
26-
:ref:`php-aggregation-builder-api` feature to create filters for other
27-
operations such as find, update, and delete operations.
26+
Aggregation Builder feature to create filters for other operations such
27+
as find, update, and delete operations. To learn more about the Aggregation
28+
Builder, see the :ref:`php-aggregation-builder-api` section of the
29+
Aggregation guide.
2830

2931
Using builders to create queries helps you identify errors at compile
3032
time and avoid them at runtime. This guide provides information on
31-
builder classes that you can use for the following tasks:
33+
builder classes that you can use to perform the following tasks:
3234

33-
- :ref:`Creating a filter definition <php-builders-filter>`
34-
- :ref:`Defining an update operation <php-builders-update>`
35-
- :ref:`Filtering a change stream <php-builders-changestream>`
35+
- :ref:`php-builders-filter`
36+
- :ref:`php-builders-update`
37+
- :ref:`php-builders-changestream`
38+
39+
.. note:: Setting Operation Options
3640

37-
.. note:: Options
38-
3941
You cannot specify options by using factory methods for the equivalent
4042
aggregation stages. For example, you cannot use the ``Stage::limit()`` method
4143
to set a returned documents limit on your find operation. You must specify
@@ -97,7 +99,7 @@ builders:
9799
1. Instantiate the ``QueryInterface`` by calling the ``Query::query()``
98100
method.
99101

100-
#. Pass the field name to compare and a factory method from the
102+
#. Pass the field name to filter on and a factory method from the
101103
``Query`` class. You can pass one or more pairs of field names and
102104
criteria to the ``QueryInterface``.
103105

@@ -187,8 +189,8 @@ You can use factory methods from the ``Stage`` builder class to update
187189
or create field values in your update operations. To learn more about
188190
updating documents, see the :ref:`php-write-update` guide.
189191

190-
.. important::
191-
192+
.. important:: Only $set Operator Supported
193+
192194
The only update operation that you can express by using builders uses
193195
the ``$set`` operator. This operator allows you to replace the value of
194196
a field with a specified value or create a new field that has a specified
@@ -218,8 +220,7 @@ This example performs the following actions:
218220

219221
- Uses the ``Query::eq()`` factory method to match documents in which
220222
the ``watlev`` field value is ``'partly submerged at high water'``
221-
- Uses builders to specify an update that sets
222-
sets the ``year`` field to ``1870``
223+
- Uses the ``Stage::set()`` method to update the ``year`` field to ``1870``
223224
- Calls the :phpmethod:`MongoDB\Collection::updateOne()`
224225
method to perform the update
225226
- Prints the number of updated documents
@@ -280,8 +281,8 @@ This example performs the following actions:
280281
- Uses the ``Stage::project()`` method to output only the specified change
281282
event fields
282283
- Calls the :phpmethod:`MongoDB\Collection::watch()`
283-
method to open the change stream with the option to output the full
284-
document after update
284+
method to open the change stream and sets the ``fullDocument`` option
285+
to output the full document after update
285286
- Prints change events as they occur
286287

287288
.. io-code-block::

source/includes/builders.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
// end-db-coll
1717

1818
// start-find
19+
/* Creates a query filter by using builders and
20+
retrieves matching documents */
1921
$docs = $collection->find(Query::query(
2022
feature_type: Query::eq('Wrecks - Visible'),
2123
coordinates: Query::near(
@@ -27,12 +29,15 @@
2729
)
2830
));
2931

32+
/* Prints matching documents */
3033
foreach ($docs as $doc) {
3134
echo json_encode($doc), PHP_EOL;
3235
}
3336
// end-find
3437

3538
// start-deleteone
39+
/* Creates a query filter by using builders
40+
and deletes the first matching document */
3641
$result = $collection->deleteOne(Query::query(
3742
feature_type: Query::regex('nondangerous$', '')
3843
));
@@ -41,6 +46,8 @@
4146
// end-deleteone
4247

4348
// start-updateone
49+
/* Creates a query filter and an update document by
50+
using builders and updates the first matching document */
4451
$result = $collection->updateOne(
4552
Query::query(watlev: Query::eq('partly submerged at high water')),
4653
new Pipeline(
@@ -52,16 +59,20 @@
5259
// end-updateone
5360

5461
// start-cs
62+
/* Creates a pipeline to filter for update operations and returns
63+
only specific fields */
5564
$pipeline = [
5665
Stage::match(operationType: Query::eq('update')),
5766
Stage::project(operationType: 1, ns: 1, fullDocument: 1),
5867
];
5968

69+
/* Opens the change stream */
6070
$changeStream = $collection->watch(
6171
$pipeline,
6272
['fullDocument' => MongoDB\Operation\Watch::FULL_DOCUMENT_UPDATE_LOOKUP]
6373
);
6474

75+
/* Prints change events based on the pipeline specifications */
6576
for ($changeStream->rewind(); true; $changeStream->next()) {
6677
if (! $changeStream->valid()) {
6778
continue;

0 commit comments

Comments
 (0)