-
Notifications
You must be signed in to change notification settings - Fork 34
DOCSP-41977: Specify documents to return #105
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
norareidy
merged 13 commits into
mongodb:php-standardization
from
norareidy:DOCSP-41977-docs-to-return
Aug 27, 2024
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3ec55d1
DOCSP-41977: Specify documents to return
norareidy a8c3af5
edits
norareidy 942bd60
code output
norareidy 51d06a6
toc
norareidy b41fef9
Merge remote-tracking branch 'upstream/php-standardization' into DOCS…
norareidy 0040abe
MM feedback, code edits
norareidy 4ca3636
edit
norareidy 56a8e0e
Merge remote-tracking branch 'upstream/php-standardization' into DOCS…
norareidy f173a48
JT feedback
norareidy 0c11a2e
edit
norareidy fbb41a1
test
norareidy 8bab89e
MM feedback 2
norareidy ec622a7
Merge remote-tracking branch 'upstream/php-standardization' into DOCS…
norareidy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| <?php | ||
|
|
||
| require 'vendor/autoload.php'; | ||
|
|
||
| $client = new MongoDB\Client('<connection string>'); | ||
|
|
||
| // 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 | ||
|
|
||
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| .. _php-read: | ||
|
|
||
| ====================== | ||
| Read Data from MongoDB | ||
| ====================== | ||
|
|
||
| .. toctree:: | ||
| :titlesonly: | ||
| :maxdepth: 1 | ||
|
|
||
| /read/specify-documents-to-return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,202 @@ | ||||||||||||||||||||||
| .. _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 <php-return-documents-limit>`: Specifies the maximum number of documents | ||||||||||||||||||||||
| to return from a query. | ||||||||||||||||||||||
| - :ref:`sort <php-return-documents-sort>`: Specifies the sort order for the returned documents. | ||||||||||||||||||||||
| - :ref:`skip <php-return-documents-skip>`: Specifies the number of documents to skip before | ||||||||||||||||||||||
| returning query results. | ||||||||||||||||||||||
|
||||||||||||||||||||||
| - :ref:`limit <php-return-documents-limit>`: Specifies the maximum number of documents | |
| to return from a query. | |
| - :ref:`sort <php-return-documents-sort>`: Specifies the sort order for the returned documents. | |
| - :ref:`skip <php-return-documents-skip>`: Specifies the number of documents to skip before | |
| returning query results. | |
| - :ref:`limit <php-return-documents-limit>`: Specifies the maximum number of documents | |
| to return from a query | |
| - :ref:`sort <php-return-documents-sort>`: Specifies the sort order for the returned documents | |
| - :ref:`skip <php-return-documents-skip>`: Specifies the number of documents to skip before | |
| returning query results |
norareidy marked this conversation as resolved.
Show resolved
Hide resolved
norareidy marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+264
to
+266
Collaborator
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.