From 3ec55d1e55616aff1013aacb3a7282a502e07dd2 Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 15 Aug 2024 11:37:02 -0400 Subject: [PATCH 01/10] DOCSP-41977: Specify documents to return --- snooty.toml | 1 + source/includes/read/limit-skip-sort.php | 63 +++++++ source/read/specify-documents-to-return.txt | 198 ++++++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 source/includes/read/limit-skip-sort.php create mode 100644 source/read/specify-documents-to-return.txt diff --git a/snooty.toml b/snooty.toml index a08a8d41..507f09d6 100644 --- a/snooty.toml +++ b/snooty.toml @@ -24,3 +24,4 @@ php-library = "MongoDB PHP Library" [constants] php-library = "MongoDB PHP Library" +api = "https://www.mongodb.com/docs/php-library/current/reference" diff --git a/source/includes/read/limit-skip-sort.php b/source/includes/read/limit-skip-sort.php new file mode 100644 index 00000000..6c83a0cf --- /dev/null +++ b/source/includes/read/limit-skip-sort.php @@ -0,0 +1,63 @@ +'); + +// start-db-coll +$db = $client->sample_restaurants; +$collection = $db->restaurants; +// end-db-coll + +// Retrieves 5 documents that have a "cuisine" value of "Italian" +// start-limit +$options = [ + 'limit' => 5, +]; +$cursor = $collection->find(['cuisine' => 'Italian'], $options); + +foreach ($cursor as $doc) { + echo json_encode($doc) . PHP_EOL; +} +// end-limit + +// Retrieves documents with a "cuisine" value of "Italian" and sorts in ascending "name" order +// start-sort +$options = [ + 'sort' => ['name' => 1], +]; + +$cursor = $collection->find(['cuisine' => 'Italian'], $options); +foreach ($cursor as $doc) { + echo json_encode($doc) . PHP_EOL; +} +// end-sort + +// Retrieves documents with a "borough" value of "Manhattan" but skips the first 10 results +// start-skip +$options = [ + 'skip' => 10, +]; + +$cursor = $collection->find(['borough' => 'Manhattan'], $options); +foreach ($cursor as $doc) { + echo json_encode($doc) . PHP_EOL; +} +// end-skip + +// Retrieves 5 documents with a "cuisine" value of "Italian", skips the first 10 results, +// and sorts by ascending "name" order +// start-limit-sort-skip +$options = [ + 'sort' => ['name' => 1], + 'limit' => 5, + 'skip' => 10, +]; + +$cursor = $collection->find(['cuisine' => 'Italian'], $options); +foreach ($cursor as $doc) { + echo json_encode($doc) . PHP_EOL; +} +// end-limit-sort-skip + +?> \ No newline at end of file diff --git a/source/read/specify-documents-to-return.txt b/source/read/specify-documents-to-return.txt new file mode 100644 index 00000000..f380f253 --- /dev/null +++ b/source/read/specify-documents-to-return.txt @@ -0,0 +1,198 @@ +.. _php-specify-documents-to-return: + +=========================== +Specify Documents to Return +=========================== + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. facet:: + :name: genre + :values: reference + +.. meta:: + :keywords: read, paginate, pagination, order, code example + +Overview +-------- + +In this guide, you can learn how to specify which documents to return from a read +operation by passing the following options to the ``MongoDB\Collection::find()`` or +``MongoDB\Collection::findOne()`` method: + +- :ref:`limit `: Specifies the maximum number of documents + to return from a query. +- :ref:`sort `: Specifies the sort order for the returned documents. +- :ref:`skip `: Specifies the number of documents to skip before + returning query results. + +Sample Data +~~~~~~~~~~~ + +The examples in this guide use the ``restaurants`` collection in the ``sample_restaurants`` +database from the :atlas:`Atlas sample datasets `. To access this collection +from your PHP application, instantiate a ``MongoDB\Client`` that connects to an Atlas cluster +and assign the following values to your ``db`` and ``collection`` variables: + +.. literalinclude:: /includes/read/project.php + :language: php + :dedent: + :start-after: start-db-coll + :end-before: end-db-coll + +To learn how to create a free MongoDB Atlas cluster and load the sample datasets, see the +:atlas:`Get Started with Atlas ` guide. + +.. _php-return-documents-limit: + +Limit +----- + +To specify the maximum number of documents returned from a read operation, create +an array that sets the ``limit`` option and pass the array as a parameter to the +``MongoDB\Collection::find()`` or ``MongoDB\Collection::findOne()`` method. + +The following example finds all restaurants that have a ``cuisine`` field value +of ``'Italian'`` and limits the results to ``5`` documents: + +.. io-code-block:: + :copyable: + + .. input:: /includes/read/limit-skip-sort.php + :start-after: start-limit + :end-before: end-limit + :language: php + :dedent: + + .. output:: + + { "_id" : { "$oid" : "..." }, ..., "name" : "Philadelphia Grille Express", "restaurant_id" : "40364305" } + { "_id" : { "$oid" : "..." }, ..., "name" : "Isle Of Capri Restaurant", "restaurant_id" : "40364373" } + { "_id" : { "$oid" : "..." }, ..., "name" : "Marchis Restaurant", "restaurant_id" : "40364668" } + { "_id" : { "$oid" : "..." }, ..., "name" : "Crystal Room", "restaurant_id" : "40365013" } + { "_id" : { "$oid" : "..." }, ..., "name" : "Forlinis Restaurant", "restaurant_id" : "40365098" } + +.. tip:: + + The preceding example returns the first five documents matched by the query + according to their :manual:`natural order ` + in the database. The following section describes how to return the documents + in a specified order. + +.. _php-return-documents-sort: + +Sort +---- + +To return documents in a specified order, create an array that sets the ``sort`` +option. When setting this option, include the field to sort the results by and +the sort direction. A value of ``1`` sorts values from lowest to highest, and +a value of ``-1`` sorts them from highest to lowest. Then, pass the array as a +parameter to the ``MongoDB\Collection::find()`` or ``MongoDB\Collection::findOne()`` +method. + +The following example returns all documents that have a ``cuisine`` value of ``'Italian'``, +sorted in ascending order of ``name`` field values: + +.. io-code-block:: + :copyable: + + .. input:: /includes/read/limit-skip-sort.php + :start-after: start-sort + :end-before: end-sort + :language: php + :dedent: + + .. output:: + + { "_id" : { "$oid" : "..." }, ..., "name" : "(Lewis Drug Store) Locanda Vini E Olii", "restaurant_id" : "40804423" } + { "_id" : { "$oid" : "..." }, ..., "name" : "101 Restaurant And Bar", "restaurant_id" : "40560108" } + { "_id" : { "$oid" : "..." }, ..., "name" : "44 Sw Ristorante & Bar", "restaurant_id" : "40698807" } + ... + { "_id" : { "$oid" : "..." }, ..., "name" : "Zucchero E Pomodori", "restaurant_id" : "41189590" } + +.. _php-return-documents-skip: + +Skip +---- + +To skip a specified number of documents before returning your query results, create +an array that sets the ``skip`` option and pass the array as a parameter to the +``MongoDB\Collection::find()`` or ``MongoDB\Collection::findOne()`` method. + +The following example returns all documents that have a ``borough`` field value +of ``'Manhattan'`` and skips the first ``10`` documents: + +.. io-code-block:: + :copyable: + + .. input:: /includes/read/limit-skip-sort.php + :start-after: start-skip + :end-before: end-skip + :language: php + :dedent: + + .. output:: + + { "_id" : { "$oid" : "..." }, ..., "name" : "Cafe Metro", "restaurant_id" : "40363298" } + { "_id" : { "$oid" : "..." }, ..., "name" : "Lexler Deli", "restaurant_id" : "40363426" } + { "_id" : { "$oid" : "..." }, ..., "name" : "Domino'S Pizza", "restaurant_id" : "40363644" } + ... + +.. _php-return-documents-combine: + +Combine Limit, Sort, and Skip +----------------------------- + +You can set the ``limit``, ``sort``, and ``skip`` options in a single +options array and pass the array as a parameter to the read operation. +This allows you to set a maximum number of sorted documents to return, +skipping a specified number of documents before returning. + +The following example returns ``5`` documents that have a ``cuisine`` value of +``'Italian'``. The results are sorted in ascending order by ``name`` field value, +skipping the first ``10`` documents: + +.. io-code-block:: + :copyable: + + .. input:: /includes/read/limit-skip-sort.php + :start-after: start-limit-sort-skip + :end-before: end-limit-sort-skip + :language: php + :dedent: + + .. output:: + + { "_id" : { "$oid" : "..." }, ..., "name" : "Acqua", "restaurant_id" : "40871070" } + { "_id" : { "$oid" : "..." }, ..., "name" : "Acqua Restaurant", "restaurant_id" : "41591488" } + { "_id" : { "$oid" : "..." }, ..., "name" : "Acqua Santa", "restaurant_id" : "40735858" } + { "_id" : { "$oid" : "..." }, ..., "name" : "Acquista Trattoria", "restaurant_id" : "40813992" } + { "_id" : { "$oid" : "..." }, ..., "name" : "Acquolina Catering", "restaurant_id" : "41381423" } + +.. note:: + + The order in which you call these methods doesn't change the documents + that are returned. The {+php-library+} automatically reorders the calls to + perform the sort operation first, the skip operation next, and then the limit + operation. + +Additional Information +---------------------- + +For more information about retrieving documents, see the :ref:`php-retrieve` guide. + +For more information about specifying a query, see the :ref:`php-specify-query` guide. + +API Documentation +~~~~~~~~~~~~~~~~~ + +To learn more about any of the methods or types discussed in this +guide, see the following API documentation: + +- `MongoDB\\Collection::findOne() <{+api+}/method/MongoDBCollection-findOne/>`__ +- `MongoDB\\Collection::find() <{+api+}/method/MongoDBCollection-find/>`__ From a8c3af58387c135e7157164460ecbfbfd200999e Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 15 Aug 2024 11:42:10 -0400 Subject: [PATCH 02/10] edits --- source/read/specify-documents-to-return.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/read/specify-documents-to-return.txt b/source/read/specify-documents-to-return.txt index f380f253..c182941b 100644 --- a/source/read/specify-documents-to-return.txt +++ b/source/read/specify-documents-to-return.txt @@ -38,7 +38,7 @@ database from the :atlas:`Atlas sample datasets `. To access this from your PHP application, instantiate a ``MongoDB\Client`` that connects to an Atlas cluster and assign the following values to your ``db`` and ``collection`` variables: -.. literalinclude:: /includes/read/project.php +.. literalinclude:: /includes/read/limit-skip-sort.php :language: php :dedent: :start-after: start-db-coll @@ -54,7 +54,7 @@ Limit To specify the maximum number of documents returned from a read operation, create an array that sets the ``limit`` option and pass the array as a parameter to the -``MongoDB\Collection::find()`` or ``MongoDB\Collection::findOne()`` method. +``MongoDB\Collection::find()`` method. The following example finds all restaurants that have a ``cuisine`` field value of ``'Italian'`` and limits the results to ``5`` documents: @@ -159,7 +159,7 @@ skipping the first ``10`` documents: .. io-code-block:: :copyable: - + .. input:: /includes/read/limit-skip-sort.php :start-after: start-limit-sort-skip :end-before: end-limit-sort-skip From 942bd606786ba0fecfef49478e9ac8aaa55c094d Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 15 Aug 2024 11:55:42 -0400 Subject: [PATCH 03/10] code output --- source/read/specify-documents-to-return.txt | 40 +++++++++++---------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/source/read/specify-documents-to-return.txt b/source/read/specify-documents-to-return.txt index c182941b..600cfd4d 100644 --- a/source/read/specify-documents-to-return.txt +++ b/source/read/specify-documents-to-return.txt @@ -69,12 +69,13 @@ of ``'Italian'`` and limits the results to ``5`` documents: :dedent: .. output:: + :visible: false - { "_id" : { "$oid" : "..." }, ..., "name" : "Philadelphia Grille Express", "restaurant_id" : "40364305" } - { "_id" : { "$oid" : "..." }, ..., "name" : "Isle Of Capri Restaurant", "restaurant_id" : "40364373" } - { "_id" : { "$oid" : "..." }, ..., "name" : "Marchis Restaurant", "restaurant_id" : "40364668" } - { "_id" : { "$oid" : "..." }, ..., "name" : "Crystal Room", "restaurant_id" : "40365013" } - { "_id" : { "$oid" : "..." }, ..., "name" : "Forlinis Restaurant", "restaurant_id" : "40365098" } + {"_id":{"$oid":"..."},...,"name":"Isle Of Capri Resturant","restaurant_id":"40364373"} + {"_id":{"$oid":"..."},...,"name":"Marchis Restaurant","restaurant_id":"40364668"} + {"_id":{"$oid":"..."},...,"name":"Crystal Room","restaurant_id":"40365013"} + {"_id":{"$oid":"..."},...,"name":"Forlinis Restaurant","restaurant_id":"40365098"} + {"_id":{"$oid":"..."},...,"name":"Angelo Of Mulberry St.","restaurant_id":"40365293"} .. tip:: @@ -108,12 +109,13 @@ sorted in ascending order of ``name`` field values: :dedent: .. output:: + :visible: false - { "_id" : { "$oid" : "..." }, ..., "name" : "(Lewis Drug Store) Locanda Vini E Olii", "restaurant_id" : "40804423" } - { "_id" : { "$oid" : "..." }, ..., "name" : "101 Restaurant And Bar", "restaurant_id" : "40560108" } - { "_id" : { "$oid" : "..." }, ..., "name" : "44 Sw Ristorante & Bar", "restaurant_id" : "40698807" } + {"_id":{"$oid":"..."},...,"name":"44 Sw Ristorante & Bar","restaurant_id":"40698807"} + {"_id":{"$oid":"..."},...,"name":"900 Park","restaurant_id":"41707964"} + {"_id":{"$oid":"..."},...,"name":"A Voce","restaurant_id":"41434084"} ... - { "_id" : { "$oid" : "..." }, ..., "name" : "Zucchero E Pomodori", "restaurant_id" : "41189590" } + {"_id":{"$oid":"..."},...,"name":"Zucchero E Pomodori","restaurant_id":"41189590" } .. _php-return-documents-skip: @@ -137,10 +139,11 @@ of ``'Manhattan'`` and skips the first ``10`` documents: :dedent: .. output:: + :visible: false - { "_id" : { "$oid" : "..." }, ..., "name" : "Cafe Metro", "restaurant_id" : "40363298" } - { "_id" : { "$oid" : "..." }, ..., "name" : "Lexler Deli", "restaurant_id" : "40363426" } - { "_id" : { "$oid" : "..." }, ..., "name" : "Domino'S Pizza", "restaurant_id" : "40363644" } + {"_id":{"$oid":"..."},...,"name":"Cafe Metro","restaurant_id":"40363298"} + {"_id":{"$oid":"..."},...,"name":"Lexler Deli","restaurant_id":"40363426"} + {"_id":{"$oid":"..."},...,"name":"Domino'S Pizza","restaurant_id":"40363644"} ... .. _php-return-documents-combine: @@ -167,12 +170,13 @@ skipping the first ``10`` documents: :dedent: .. output:: - - { "_id" : { "$oid" : "..." }, ..., "name" : "Acqua", "restaurant_id" : "40871070" } - { "_id" : { "$oid" : "..." }, ..., "name" : "Acqua Restaurant", "restaurant_id" : "41591488" } - { "_id" : { "$oid" : "..." }, ..., "name" : "Acqua Santa", "restaurant_id" : "40735858" } - { "_id" : { "$oid" : "..." }, ..., "name" : "Acquista Trattoria", "restaurant_id" : "40813992" } - { "_id" : { "$oid" : "..." }, ..., "name" : "Acquolina Catering", "restaurant_id" : "41381423" } + :visible: false + + {"_id":{"$oid":"..."},...,"name":"Acqua","restaurant_id":"40871070"} + {"_id":{"$oid":"..."},...,"name":"Acqua Restaurant","restaurant_id":"41591488"} + {"_id":{"$oid":"..."},...,"name":"Acqua Santa","restaurant_id":"40735858"} + {"_id":{"$oid":"..."},...,"name":"Acquista Trattoria","restaurant_id":"40813992"} + {"_id":{"$oid":"..."},...,"name":"Acquolina Catering","restaurant_id":"41381423"} .. note:: From 51d06a6a6d718e2f7ef9de9e5d05a090bf0b0600 Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 15 Aug 2024 11:57:32 -0400 Subject: [PATCH 04/10] toc --- source/index.txt | 1 + source/read.txt | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 source/read.txt diff --git a/source/index.txt b/source/index.txt index 244f3eb2..26734024 100644 --- a/source/index.txt +++ b/source/index.txt @@ -12,6 +12,7 @@ MongoDB PHP Library Installation Get Started + /read /tutorial /upgrade /reference diff --git a/source/read.txt b/source/read.txt new file mode 100644 index 00000000..39f2349f --- /dev/null +++ b/source/read.txt @@ -0,0 +1,11 @@ +.. _php-read: + +====================== +Read Data from MongoDB +====================== + +.. toctree:: + :titlesonly: + :maxdepth: 1 + + /read/specify-documents-to-return \ No newline at end of file From 0040abe2217fda9d71b12789e71583d6033814f2 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 19 Aug 2024 17:26:00 -0400 Subject: [PATCH 05/10] MM feedback, code edits --- source/includes/read/limit-skip-sort.php | 32 ++++++++++----------- source/read/specify-documents-to-return.txt | 2 +- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/source/includes/read/limit-skip-sort.php b/source/includes/read/limit-skip-sort.php index 6c83a0cf..b13402ce 100644 --- a/source/includes/read/limit-skip-sort.php +++ b/source/includes/read/limit-skip-sort.php @@ -2,19 +2,19 @@ require 'vendor/autoload.php'; -$client = new MongoDB\Client(''); +$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); // start-db-coll -$db = $client->sample_restaurants; -$collection = $db->restaurants; +$collection = $client->sample_restaurants->restaurants; // end-db-coll // Retrieves 5 documents that have a "cuisine" value of "Italian" // start-limit -$options = [ - 'limit' => 5, -]; -$cursor = $collection->find(['cuisine' => 'Italian'], $options); +$cursor = $collection->find( + ['cuisine' => 'Italian'], + ['limit' => 5] +); foreach ($cursor as $doc) { echo json_encode($doc) . PHP_EOL; @@ -23,11 +23,11 @@ // Retrieves documents with a "cuisine" value of "Italian" and sorts in ascending "name" order // start-sort -$options = [ - 'sort' => ['name' => 1], -]; +$cursor = $collection->find( + ['cuisine' => 'Italian'], + ['sort' => ['name' => 1]] +); -$cursor = $collection->find(['cuisine' => 'Italian'], $options); foreach ($cursor as $doc) { echo json_encode($doc) . PHP_EOL; } @@ -35,11 +35,11 @@ // Retrieves documents with a "borough" value of "Manhattan" but skips the first 10 results // start-skip -$options = [ - 'skip' => 10, -]; +$cursor = $collection->find( + ['borough' => 'Manhattan'], + ['skip' => 10] +); -$cursor = $collection->find(['borough' => 'Manhattan'], $options); foreach ($cursor as $doc) { echo json_encode($doc) . PHP_EOL; } @@ -59,5 +59,3 @@ echo json_encode($doc) . PHP_EOL; } // end-limit-sort-skip - -?> \ No newline at end of file diff --git a/source/read/specify-documents-to-return.txt b/source/read/specify-documents-to-return.txt index 600cfd4d..4f53038c 100644 --- a/source/read/specify-documents-to-return.txt +++ b/source/read/specify-documents-to-return.txt @@ -36,7 +36,7 @@ Sample Data The examples in this guide use the ``restaurants`` collection in the ``sample_restaurants`` database from the :atlas:`Atlas sample datasets `. To access this collection from your PHP application, instantiate a ``MongoDB\Client`` that connects to an Atlas cluster -and assign the following values to your ``db`` and ``collection`` variables: +and assign the following value to your ``collection`` variable: .. literalinclude:: /includes/read/limit-skip-sort.php :language: php From 4ca363639da64a43e29670fdac45317a1d75abfe Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 19 Aug 2024 17:27:33 -0400 Subject: [PATCH 06/10] edit --- source/read/specify-documents-to-return.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/read/specify-documents-to-return.txt b/source/read/specify-documents-to-return.txt index 4f53038c..f1cc47e1 100644 --- a/source/read/specify-documents-to-return.txt +++ b/source/read/specify-documents-to-return.txt @@ -25,10 +25,10 @@ operation by passing the following options to the ``MongoDB\Collection::find()`` ``MongoDB\Collection::findOne()`` method: - :ref:`limit `: Specifies the maximum number of documents - to return from a query. -- :ref:`sort `: Specifies the sort order for the returned documents. + to return from a query +- :ref:`sort `: Specifies the sort order for the returned documents - :ref:`skip `: Specifies the number of documents to skip before - returning query results. + returning query results Sample Data ~~~~~~~~~~~ From f173a4870b8af85267ec65240663d2a327a5fa05 Mon Sep 17 00:00:00 2001 From: norareidy Date: Fri, 23 Aug 2024 11:27:36 -0400 Subject: [PATCH 07/10] JT feedback --- source/includes/read/limit-skip-sort.php | 15 +++++ source/read/specify-documents-to-return.txt | 66 +++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/source/includes/read/limit-skip-sort.php b/source/includes/read/limit-skip-sort.php index b13402ce..3ab8a16f 100644 --- a/source/includes/read/limit-skip-sort.php +++ b/source/includes/read/limit-skip-sort.php @@ -59,3 +59,18 @@ echo json_encode($doc) . PHP_EOL; } // end-limit-sort-skip + +// Returns documents with a "cuisine" value of "Hawaiian" as arrays +// start-return-type +$options = [ + 'typeMap' => [ + 'root' => 'array', + 'document' => 'array' + ] +]; + +$cursor = $collection->find(['cuisine' => 'Hawaiian'], $options); +foreach ($cursor as $doc) { + print_r($doc) . PHP_EOL; +} +// end-return-type diff --git a/source/read/specify-documents-to-return.txt b/source/read/specify-documents-to-return.txt index f1cc47e1..11bdcced 100644 --- a/source/read/specify-documents-to-return.txt +++ b/source/read/specify-documents-to-return.txt @@ -185,6 +185,72 @@ skipping the first ``10`` documents: perform the sort operation first, the skip operation next, and then the limit operation. +.. _php-return-documents-type: + +Specify Return Type +------------------- + +To customize the data type of documents returned by a read operation, you can pass the +``typeMap`` option in an array parameter. + +By default, methods called on a ``MongoDB\Client``, ``MongoDB\Database``, or ``MongoDB\Collection`` +instance use the following type map: + +.. code-block:: php + + [ + 'array' => 'MongoDB\Model\BSONArray', + 'document' => 'MongoDB\Model\BSONDocument', + 'root' => 'MongoDB\Model\BSONDocument', + ] + +This default type map performs the following conversions: + +- Arrays to ``MongoDB\Model\BSONArray`` objects +- Top-level and embedded BSON documents to ``MongoDB\Model\BSONDocument`` objects + +In a custom type map, you can specify conversions to any type that implements +``MongoDB\BSON\Unserializable``, as well as the ``array``, ``stdClass``, and ``object`` +types. The following example returns all documents that have a ``cuisine`` value of ``'Hawaiian'`` +and specifies the ``typeMap`` option to convert the documents to array values: + +.. io-code-block:: + :copyable: + + .. input:: /includes/read/limit-skip-sort.php + :start-after: start-return-type + :end-before: end-return-type + :language: php + :dedent: + + .. output:: + :visible: false + + Array + ( + [_id] => MongoDB\BSON\ObjectId Object + ( + [oid] => ... + ) + + [address] => Array + ( + ... + ) + + [borough] => Manhattan + [cuisine] => Hawaiian + [grades] => Array + ( + ... + + ) + + [name] => Makana + [restaurant_id] => 41509012 + ) + ... + Additional Information ---------------------- From 0c11a2e99ed8811d7f4860bca6fa97d65b4266bc Mon Sep 17 00:00:00 2001 From: norareidy Date: Fri, 23 Aug 2024 11:40:42 -0400 Subject: [PATCH 08/10] edit --- source/read/specify-documents-to-return.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/source/read/specify-documents-to-return.txt b/source/read/specify-documents-to-return.txt index 11bdcced..50ade1f0 100644 --- a/source/read/specify-documents-to-return.txt +++ b/source/read/specify-documents-to-return.txt @@ -20,15 +20,17 @@ Specify Documents to Return Overview -------- -In this guide, you can learn how to specify which documents to return from a read -operation by passing the following options to the ``MongoDB\Collection::find()`` or -``MongoDB\Collection::findOne()`` method: +In this guide, you can learn how to specify which documents and which types to return +from a read operation by passing the following options to the ``MongoDB\Collection::find()`` +or ``MongoDB\Collection::findOne()`` method: - :ref:`limit `: Specifies the maximum number of documents to return from a query - :ref:`sort `: Specifies the sort order for the returned documents - :ref:`skip `: Specifies the number of documents to skip before returning query results +- :ref:`typeMap `: Converts the returned documents to a specified data + type Sample Data ~~~~~~~~~~~ From fbb41a10e70dc06b7707479875cfd309bfc93d31 Mon Sep 17 00:00:00 2001 From: norareidy Date: Fri, 23 Aug 2024 11:43:49 -0400 Subject: [PATCH 09/10] test From 8bab89e64c88d195966c2aa503e71f66b46413bb Mon Sep 17 00:00:00 2001 From: norareidy Date: Fri, 23 Aug 2024 12:03:13 -0400 Subject: [PATCH 10/10] MM feedback 2 --- source/read/specify-documents-to-return.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/read/specify-documents-to-return.txt b/source/read/specify-documents-to-return.txt index 50ade1f0..4497569f 100644 --- a/source/read/specify-documents-to-return.txt +++ b/source/read/specify-documents-to-return.txt @@ -213,7 +213,12 @@ This default type map performs the following conversions: In a custom type map, you can specify conversions to any type that implements ``MongoDB\BSON\Unserializable``, as well as the ``array``, ``stdClass``, and ``object`` -types. The following example returns all documents that have a ``cuisine`` value of ``'Hawaiian'`` +types. + +Example +~~~~~~~ + +The following example returns all documents that have a ``cuisine`` value of ``'Hawaiian'`` and specifies the ``typeMap`` option to convert the documents to array values: .. io-code-block::