From baa60ec18c6377b56083613b14cbcfac5387fc44 Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 27 Aug 2024 15:17:40 -0400 Subject: [PATCH 1/9] DOCSP-41988: Aggregation --- source/aggregation.txt | 193 ++++++++++++++++++++++++++++++++ source/includes/aggregation.php | 42 +++++++ 2 files changed, 235 insertions(+) create mode 100644 source/aggregation.txt create mode 100644 source/includes/aggregation.php diff --git a/source/aggregation.txt b/source/aggregation.txt new file mode 100644 index 00000000..cbe9b9bd --- /dev/null +++ b/source/aggregation.txt @@ -0,0 +1,193 @@ +.. _php-aggregation: + +==================================== +Transform Your Data with Aggregation +==================================== + +.. facet:: + :name: genre + :values: reference + +.. meta:: + :keywords: code example, transform, computed, pipeline + :description: Learn how to use the PHP library to perform aggregation operations. + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. TODO: + .. toctree:: + :titlesonly: + :maxdepth: 1 + + /aggregation/aggregation-tutorials + +Overview +-------- + +In this guide, you can learn how to use the {+php-library+} to perform +**aggregation operations**. + +Aggregation operations process data in your MongoDB collections and +return computed results. The MongoDB Aggregation framework, which is +part of the Query API, is modeled on the concept of data processing +pipelines. Documents enter a pipeline that contains one or more stages, +and this pipeline transforms the documents into an aggregated result. + +An aggregation operation is similar to a car factory. A car factory has +an assembly line, which contains assembly stations with specialized +tools to do specific jobs, like drills and welders. Raw parts enter the +factory, and then the assembly line transforms and assembles them into a +finished product. + +The **aggregation pipeline** is the assembly line, **aggregation stages** are the +assembly stations, and **operator expressions** are the +specialized tools. + +Aggregation Versus Find Operations +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +You can use find operations to perform the following actions: + +- Select which documents to return +- Select which fields to return +- Sort the results + +You can use aggregation operations to perform the following actions: + +- Run find operations +- Rename fields +- Calculate fields +- Summarize data +- Group values + +Limitations +~~~~~~~~~~~ + +Keep the following limitations in mind when using aggregation operations: + +- Returned documents cannot violate the + :manual:`BSON document size limit ` + of 16 megabytes. +- Pipeline stages have a memory limit of 100 megabytes by default. You can exceed this + limit by creating an options array that sets the ``allowDiskUse`` option to ``true`` + and passing the array to the ``MongoDB\Collection::aggregate()`` method. + +.. important:: $graphLookup Exception + + The :manual:`$graphLookup + ` stage has a strict + memory limit of 100 megabytes and ignores the ``allowDiskUse`` option. + +.. _php-aggregation-example: + +Aggregation Example +------------------- + +.. note:: + + The examples in this guide use the ``restaurants`` collection in the ``sample_restaurants`` + database from the :atlas:`Atlas sample datasets `. To learn how to create a + free MongoDB Atlas cluster and load the sample datasets, see the :atlas:`Get Started with Atlas + ` guide. + +To perform an aggregation, pass an array containing the aggregation pipeline +stages to the ``MongoDB\Collection::aggregate()`` method. + +The following code example produces a count of the number of bakeries in each borough +of New York. To do so, it uses an aggregation pipeline that contains the following stages: + +- :manual:`$match ` stage to filter for documents + in which the ``cuisine`` field contains the value ``'Bakery'`` + +- :manual:`$group ` stage to group the matching + documents by the ``borough`` field, accumulating a count of documents for each distinct + value + +.. io-code-block:: + + .. input:: /includes/aggregation.php + :start-after: start-match-group + :end-before: end-match-group + :language: php + :dedent: + + .. output:: + + {"_id":"Brooklyn","count":173} + {"_id":"Queens","count":204} + {"_id":"Bronx","count":71} + {"_id":"Staten Island","count":20} + {"_id":"Missing","count":2} + {"_id":"Manhattan","count":221} + +Explain an Aggregation +~~~~~~~~~~~~~~~~~~~~~~ + +To view information about how MongoDB executes your operation, you can +instruct the MongoDB query planner to **explain** it. When MongoDB explains +an operation, it returns **execution plans** and performance statistics. +An execution plan is a potential way MongoDB can complete an operation. +When you instruct MongoDB to explain an operation, it returns both the +plan MongoDB executed and any rejected execution plans. + +To explain an aggregation operation, run the ``explain`` database command by passing +the command information to the ``MongoDB\Database::command()`` method. You must set the +``aggregate``, ``pipeline``, and ``cursor`` fields of the ``explain`` command document +to explain the aggregation. + +The following example instructs MongoDB to explain the aggregation operation from the +preceding :ref:`php-aggregation-example`: + +.. io-code-block:: + + .. input:: /includes/aggregation.php + :start-after: start-explain + :end-before: end-explain + :language: php + :dedent: + + .. output:: + + {"explainVersion":"2","queryPlanner":{"namespace":"sample_restaurants.restaurants", + "indexFilterSet":false,"parsedQuery":{"cuisine":{"$eq":"Bakery"}},"queryHash":"865F14C3", + "planCacheKey":"D56D6F10","optimizedPipeline":true,"maxIndexedOrSolutionsReached":false, + "maxIndexedAndSolutionsReached":false,"maxScansToExplodeReached":false,"winningPlan":{ + ... } + + +Additional Information +---------------------- + +MongoDB Server Manual +~~~~~~~~~~~~~~~~~~~~~ + +To view a full list of expression operators, see :manual:`Aggregation +Operators. ` + +To learn about assembling an aggregation pipeline and view examples, see +:manual:`Aggregation Pipeline. ` + +To learn more about creating pipeline stages, see :manual:`Aggregation +Stages. ` + +To learn more about explaining MongoDB operations, see +:manual:`Explain Output ` and +:manual:`Query Plans. ` + +.. TODO: + Aggregation Tutorials + ~~~~~~~~~~~~~~~~~~~~~ + +.. To view step-by-step explanations of common aggregation tasks, see +.. :ref:`php-aggregation-tutorials-landing`. + +API Documentation +~~~~~~~~~~~~~~~~~ + +For more information about executing aggregation operations by using the {+php-library+}, +see `MongoDB\\Collection::aggregate() <{+api+}/method/MongoDBCollection-aggregate/>`__ in +the API documentation. \ No newline at end of file diff --git a/source/includes/aggregation.php b/source/includes/aggregation.php new file mode 100644 index 00000000..9c74ad66 --- /dev/null +++ b/source/includes/aggregation.php @@ -0,0 +1,42 @@ +sample_restaurants->restaurants; + +// Retrieves documents with a cuisine value of "Bakery", groups them by "borough", and +// counts each borough's matching documents +// start-match-group +$pipeline = [ + ['$match' => ['cuisine' => 'Bakery']], + ['$group' => ['_id' => '$borough', 'count' => ['$sum' => 1]]] +]; + +$cursor = $collection->aggregate($pipeline); + +foreach ($cursor as $doc) { + echo json_encode($doc) . PHP_EOL; +} +// end-match-group + +// Performs the same aggregation operation as above but asks MongoDB to explain it +// start-explain +$pipeline = [ + ['$match' => ['cuisine' => 'Bakery']], + ['$group' => ['_id' => '$borough', 'count' => ['$sum' => 1]]] +]; + +$command = [ + 'explain' => [ + 'aggregate' => 'restaurants', + 'pipeline' => $pipeline, + 'cursor' => new stdClass() + ] +]; + +$result = $db->command($command)->toArray(); +echo json_encode($result[0]) . PHP_EOL; +// end-explain + From 6f5c0a4f31725d846eec11764d7bbbe8dd209d6f Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 27 Aug 2024 15:21:46 -0400 Subject: [PATCH 2/9] toc --- source/index.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/source/index.txt b/source/index.txt index 38ff991f..20a17130 100644 --- a/source/index.txt +++ b/source/index.txt @@ -12,6 +12,7 @@ MongoDB PHP Library Get Started /read + /aggregation /tutorial /upgrade /reference From c6c03cbfc7c9e7845fddd6510dc551bdf943bf8c Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 27 Aug 2024 15:24:38 -0400 Subject: [PATCH 3/9] edits --- source/aggregation.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/aggregation.txt b/source/aggregation.txt index cbe9b9bd..b3557d70 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -108,6 +108,7 @@ of New York. To do so, it uses an aggregation pipeline that contains the followi value .. io-code-block:: + :copyable: .. input:: /includes/aggregation.php :start-after: start-match-group @@ -116,7 +117,8 @@ of New York. To do so, it uses an aggregation pipeline that contains the followi :dedent: .. output:: - + :visible: false + {"_id":"Brooklyn","count":173} {"_id":"Queens","count":204} {"_id":"Bronx","count":71} @@ -143,6 +145,7 @@ The following example instructs MongoDB to explain the aggregation operation fro preceding :ref:`php-aggregation-example`: .. io-code-block:: + :copyable: .. input:: /includes/aggregation.php :start-after: start-explain @@ -151,6 +154,7 @@ preceding :ref:`php-aggregation-example`: :dedent: .. output:: + :visible: false {"explainVersion":"2","queryPlanner":{"namespace":"sample_restaurants.restaurants", "indexFilterSet":false,"parsedQuery":{"cuisine":{"$eq":"Bakery"}},"queryHash":"865F14C3", From 4fcfaf5d30d98bf03e918f9f0ae4880180a0fa7c Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 27 Aug 2024 15:31:47 -0400 Subject: [PATCH 4/9] code edit --- source/includes/aggregation.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/includes/aggregation.php b/source/includes/aggregation.php index 9c74ad66..05cb3316 100644 --- a/source/includes/aggregation.php +++ b/source/includes/aggregation.php @@ -4,7 +4,8 @@ $uri = getenv('MONGODB_URI') ?: throw new RuntimeException('Set the MONGODB_URI variable to your Atlas URI that connects to the sample dataset'); $client = new MongoDB\Client($uri); -$collection = $client->sample_restaurants->restaurants; +$db = $client->sample_restaurants; +$collection = $db->restaurants; // Retrieves documents with a cuisine value of "Bakery", groups them by "borough", and // counts each borough's matching documents From 6a7923159a08c477f4efd981b8c37941e0a9e298 Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 27 Aug 2024 17:22:49 -0400 Subject: [PATCH 5/9] JS feedback --- source/aggregation.txt | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/source/aggregation.txt b/source/aggregation.txt index b3557d70..8ac0d5d3 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -67,7 +67,7 @@ You can use aggregation operations to perform the following actions: Limitations ~~~~~~~~~~~ -Keep the following limitations in mind when using aggregation operations: +Consider the following limitations when performing aggregation operations: - Returned documents cannot violate the :manual:`BSON document size limit ` @@ -76,11 +76,11 @@ Keep the following limitations in mind when using aggregation operations: limit by creating an options array that sets the ``allowDiskUse`` option to ``true`` and passing the array to the ``MongoDB\Collection::aggregate()`` method. -.. important:: $graphLookup Exception + .. important:: $graphLookup Exception - The :manual:`$graphLookup - ` stage has a strict - memory limit of 100 megabytes and ignores the ``allowDiskUse`` option. + The :manual:`$graphLookup + ` stage has a strict + memory limit of 100 megabytes and ignores the ``allowDiskUse`` option. .. _php-aggregation-example: @@ -118,7 +118,7 @@ of New York. To do so, it uses an aggregation pipeline that contains the followi .. output:: :visible: false - + {"_id":"Brooklyn","count":173} {"_id":"Queens","count":204} {"_id":"Bronx","count":71} @@ -132,13 +132,13 @@ Explain an Aggregation To view information about how MongoDB executes your operation, you can instruct the MongoDB query planner to **explain** it. When MongoDB explains an operation, it returns **execution plans** and performance statistics. -An execution plan is a potential way MongoDB can complete an operation. +An execution plan is a potential way in which MongoDB can complete an operation. When you instruct MongoDB to explain an operation, it returns both the plan MongoDB executed and any rejected execution plans. To explain an aggregation operation, run the ``explain`` database command by passing -the command information to the ``MongoDB\Database::command()`` method. You must set the -``aggregate``, ``pipeline``, and ``cursor`` fields of the ``explain`` command document +the command information to the ``MongoDB\Database::command()`` method. You must specify the +``aggregate``, ``pipeline``, and ``cursor`` fields in the ``explain`` command document to explain the aggregation. The following example instructs MongoDB to explain the aggregation operation from the @@ -169,18 +169,21 @@ Additional Information MongoDB Server Manual ~~~~~~~~~~~~~~~~~~~~~ -To view a full list of expression operators, see :manual:`Aggregation -Operators. ` +To learn more about the topics discussed in this guide, see the following +pages in the {+mdb-server+} manual: + +- To view a full list of expression operators, see :manual:`Aggregation + Operators `. -To learn about assembling an aggregation pipeline and view examples, see -:manual:`Aggregation Pipeline. ` +- To learn about assembling an aggregation pipeline and to view examples, see + :manual:`Aggregation Pipeline `. -To learn more about creating pipeline stages, see :manual:`Aggregation -Stages. ` +- To learn more about creating pipeline stages, see :manual:`Aggregation + Stages `. -To learn more about explaining MongoDB operations, see -:manual:`Explain Output ` and -:manual:`Query Plans. ` +- To learn more about explaining MongoDB operations, see + :manual:`Explain Output ` and + :manual:`Query Plans `. .. TODO: Aggregation Tutorials From 6132ff6a97e323a5996bedf81209ee6f6f9569cf Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 4 Sep 2024 10:01:51 -0400 Subject: [PATCH 6/9] dev center --- source/aggregation.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/aggregation.txt b/source/aggregation.txt index 8ac0d5d3..47360f83 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -166,6 +166,11 @@ preceding :ref:`php-aggregation-example`: Additional Information ---------------------- +To view a tutorial that uses the {+php-library+} to create complex aggregation +pipelines, see `Complex Aggregation Pipelines with Vanilla PHP and MongoDB +`__ +in the MongoDB Developer Center. + MongoDB Server Manual ~~~~~~~~~~~~~~~~~~~~~ From 967767e783e4d5cc4193927a9af1d7aee37357cd Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 5 Sep 2024 16:55:26 -0400 Subject: [PATCH 7/9] JM feedback --- source/aggregation.txt | 16 +++++++--------- source/includes/aggregation.php | 23 ++++++++++------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/source/aggregation.txt b/source/aggregation.txt index 47360f83..21df5a1c 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -94,8 +94,8 @@ Aggregation Example free MongoDB Atlas cluster and load the sample datasets, see the :atlas:`Get Started with Atlas ` guide. -To perform an aggregation, pass an array containing the aggregation pipeline -stages to the ``MongoDB\Collection::aggregate()`` method. +To perform an aggregation, pass an array containing the pipeline stages to +the ``MongoDB\Collection::aggregate()`` method. The following code example produces a count of the number of bakeries in each borough of New York. To do so, it uses an aggregation pipeline that contains the following stages: @@ -136,13 +136,12 @@ An execution plan is a potential way in which MongoDB can complete an operation. When you instruct MongoDB to explain an operation, it returns both the plan MongoDB executed and any rejected execution plans. -To explain an aggregation operation, run the ``explain`` database command by passing -the command information to the ``MongoDB\Database::command()`` method. You must specify the -``aggregate``, ``pipeline``, and ``cursor`` fields in the ``explain`` command document -to explain the aggregation. +To explain an aggregation operation, construct a ``MongoDB\Operation\Aggregate`` object +and pass the database, collection, and pipeline stages as parameters. Then, pass the +``MongoDB\Operation\Aggregate`` object to the ``MongoDB\Collection::explain()`` method. -The following example instructs MongoDB to explain the aggregation operation from the -preceding :ref:`php-aggregation-example`: +The following example instructs MongoDB to explain the aggregation operation +from the preceding :ref:`php-aggregation-example`: .. io-code-block:: :copyable: @@ -162,7 +161,6 @@ preceding :ref:`php-aggregation-example`: "maxIndexedAndSolutionsReached":false,"maxScansToExplodeReached":false,"winningPlan":{ ... } - Additional Information ---------------------- diff --git a/source/includes/aggregation.php b/source/includes/aggregation.php index 05cb3316..6379bd99 100644 --- a/source/includes/aggregation.php +++ b/source/includes/aggregation.php @@ -4,15 +4,14 @@ $uri = getenv('MONGODB_URI') ?: throw new RuntimeException('Set the MONGODB_URI variable to your Atlas URI that connects to the sample dataset'); $client = new MongoDB\Client($uri); -$db = $client->sample_restaurants; -$collection = $db->restaurants; +$collection = $client->sample_restaurants->restaurants; // Retrieves documents with a cuisine value of "Bakery", groups them by "borough", and // counts each borough's matching documents // start-match-group $pipeline = [ ['$match' => ['cuisine' => 'Bakery']], - ['$group' => ['_id' => '$borough', 'count' => ['$sum' => 1]]] + ['$group' => ['_id' => '$borough', 'count' => ['$sum' => 1]]], ]; $cursor = $collection->aggregate($pipeline); @@ -26,18 +25,16 @@ // start-explain $pipeline = [ ['$match' => ['cuisine' => 'Bakery']], - ['$group' => ['_id' => '$borough', 'count' => ['$sum' => 1]]] + ['$group' => ['_id' => '$borough', 'count' => ['$sum' => 1]]], ]; -$command = [ - 'explain' => [ - 'aggregate' => 'restaurants', - 'pipeline' => $pipeline, - 'cursor' => new stdClass() - ] -]; +$aggregate = new MongoDB\Operation\Aggregate( + $collection->getDatabaseName(), + $collection->getCollectionName(), + $pipeline +); -$result = $db->command($command)->toArray(); -echo json_encode($result[0]) . PHP_EOL; +$result = $collection->explain($aggregate); +echo json_encode($result) . PHP_EOL; // end-explain From d29b6c553094f3f10d8f8d6d737a197d8bcc2a44 Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 5 Sep 2024 16:59:50 -0400 Subject: [PATCH 8/9] explain api link --- source/aggregation.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/aggregation.txt b/source/aggregation.txt index 21df5a1c..1a677c95 100644 --- a/source/aggregation.txt +++ b/source/aggregation.txt @@ -198,6 +198,8 @@ pages in the {+mdb-server+} manual: API Documentation ~~~~~~~~~~~~~~~~~ -For more information about executing aggregation operations by using the {+php-library+}, -see `MongoDB\\Collection::aggregate() <{+api+}/method/MongoDBCollection-aggregate/>`__ in -the API documentation. \ No newline at end of file +To learn more about the methods discussed in this guide, see the +following API documentation: + +- `MongoDB\\Collection::aggregate() <{+api+}/method/MongoDBCollection-aggregate/>`__ +- `MongoDB\\Collection::explain() <{+api+}/method/MongoDBCollection-explain/>`__ From 58ec2527490b81c37e16b903b93db48ebbf70068 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 9 Sep 2024 15:01:10 -0400 Subject: [PATCH 9/9] JM feedback 2 --- source/includes/aggregation.php | 4 ++-- source/includes/read/limit-skip-sort.php | 8 ++++---- source/includes/read/project.php | 6 +++--- source/includes/read/retrieve.php | 6 +++--- source/includes/read/specify-queries.php | 14 +++++++------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/source/includes/aggregation.php b/source/includes/aggregation.php index 6379bd99..e2cfa914 100644 --- a/source/includes/aggregation.php +++ b/source/includes/aggregation.php @@ -17,7 +17,7 @@ $cursor = $collection->aggregate($pipeline); foreach ($cursor as $doc) { - echo json_encode($doc) . PHP_EOL; + echo json_encode($doc) , PHP_EOL; } // end-match-group @@ -35,6 +35,6 @@ ); $result = $collection->explain($aggregate); -echo json_encode($result) . PHP_EOL; +echo json_encode($result) , PHP_EOL; // end-explain diff --git a/source/includes/read/limit-skip-sort.php b/source/includes/read/limit-skip-sort.php index 3ab8a16f..8beec933 100644 --- a/source/includes/read/limit-skip-sort.php +++ b/source/includes/read/limit-skip-sort.php @@ -17,7 +17,7 @@ ); foreach ($cursor as $doc) { - echo json_encode($doc) . PHP_EOL; + echo json_encode($doc) , PHP_EOL; } // end-limit @@ -29,7 +29,7 @@ ); foreach ($cursor as $doc) { - echo json_encode($doc) . PHP_EOL; + echo json_encode($doc) , PHP_EOL; } // end-sort @@ -41,7 +41,7 @@ ); foreach ($cursor as $doc) { - echo json_encode($doc) . PHP_EOL; + echo json_encode($doc) , PHP_EOL; } // end-skip @@ -56,7 +56,7 @@ $cursor = $collection->find(['cuisine' => 'Italian'], $options); foreach ($cursor as $doc) { - echo json_encode($doc) . PHP_EOL; + echo json_encode($doc) , PHP_EOL; } // end-limit-sort-skip diff --git a/source/includes/read/project.php b/source/includes/read/project.php index 1e7c42f3..3f63d93b 100644 --- a/source/includes/read/project.php +++ b/source/includes/read/project.php @@ -21,7 +21,7 @@ $cursor = $collection->find(['name' => 'Emerald Pub'], $options); foreach ($cursor as $doc) { - echo json_encode($doc) . PHP_EOL; + echo json_encode($doc) , PHP_EOL; } // end-project-include @@ -39,7 +39,7 @@ $cursor = $collection->find(['name' => 'Emerald Pub'], $options); foreach ($cursor as $doc) { - echo json_encode($doc) . PHP_EOL; + echo json_encode($doc) , PHP_EOL; } // end-project-include-without-id @@ -54,6 +54,6 @@ $cursor = $collection->find(['name' => 'Emerald Pub'], $options); foreach ($cursor as $doc) { - echo json_encode($doc) . PHP_EOL; + echo json_encode($doc) , PHP_EOL; } // end-project-exclude diff --git a/source/includes/read/retrieve.php b/source/includes/read/retrieve.php index fbd64a0d..ed086984 100644 --- a/source/includes/read/retrieve.php +++ b/source/includes/read/retrieve.php @@ -11,7 +11,7 @@ // Finds one document with a "name" value of "LinkedIn" // start-find-one $document = $collection->findOne(['name' => 'LinkedIn']); -echo json_encode($document) . "\n"; +echo json_encode($document) , "\n"; // end-find-one // Finds documents with a "founded_year" value of 1970 @@ -22,7 +22,7 @@ // Prints documents with a "founded_year" value of 1970 // start-cursor foreach ($results as $doc) { - echo json_encode($doc) . "\n"; + echo json_encode($doc) , "\n"; } // end-cursor @@ -34,6 +34,6 @@ ); foreach ($results as $doc) { - echo json_encode($doc) . "\n"; + echo json_encode($doc) , "\n"; } // end-modify diff --git a/source/includes/read/specify-queries.php b/source/includes/read/specify-queries.php index 3e3c07cb..df7e1c11 100644 --- a/source/includes/read/specify-queries.php +++ b/source/includes/read/specify-queries.php @@ -50,7 +50,7 @@ // start-find-exact $cursor = $collection->find(['color' => 'yellow']); foreach ($cursor as $doc) { - echo json_encode($doc) . PHP_EOL; + echo json_encode($doc) , PHP_EOL; } // end-find-exact @@ -58,7 +58,7 @@ // start-find-all $cursor = $collection->find([]); foreach ($cursor as $doc) { - echo json_encode($doc) . PHP_EOL; + echo json_encode($doc) , PHP_EOL; } // end-find-all @@ -66,7 +66,7 @@ // start-find-comparison $cursor = $collection->find(['rating' => ['$gt' => 2]]); foreach ($cursor as $doc) { - echo json_encode($doc) . PHP_EOL; + echo json_encode($doc) , PHP_EOL; } // end-find-comparison @@ -79,7 +79,7 @@ ] ]); foreach ($cursor as $doc) { - echo json_encode($doc) . PHP_EOL; + echo json_encode($doc) , PHP_EOL; } // end-find-logical @@ -87,7 +87,7 @@ // start-find-array $cursor = $collection->find(['type' => ['$size' => 2]]); foreach ($cursor as $doc) { - echo json_encode($doc) . PHP_EOL; + echo json_encode($doc) , PHP_EOL; } // end-find-array @@ -95,7 +95,7 @@ // start-find-element $cursor = $collection->find(['color' => ['$exists' => true]]); foreach ($cursor as $doc) { - echo json_encode($doc) . PHP_EOL; + echo json_encode($doc) , PHP_EOL; } // end-find-element @@ -103,6 +103,6 @@ // start-find-evaluation $cursor = $collection->find(['name' => ['$regex' => 'p{2,}']]); foreach ($cursor as $doc) { - echo json_encode($doc) . PHP_EOL; + echo json_encode($doc) , PHP_EOL; } // end-find-evaluation