-
Notifications
You must be signed in to change notification settings - Fork 34
DOCSP-41985: compound idx #141
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
rustagir
merged 2 commits into
mongodb:php-standardization
from
rustagir:DOCSP-41985-compound-idx
Sep 17, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,86 @@ | ||
.. _php-compound-index: | ||
|
||
================ | ||
Compound Indexes | ||
================ | ||
|
||
.. contents:: On this page | ||
:local: | ||
:backlinks: none | ||
:depth: 2 | ||
:class: singlecol | ||
|
||
.. facet:: | ||
:name: genre | ||
:values: reference | ||
|
||
.. meta:: | ||
:keywords: index, query, optimization, efficiency | ||
|
||
Overview | ||
-------- | ||
|
||
**Compound indexes** hold references to multiple | ||
fields within a collection's documents, improving query and sort | ||
performance. You can create a multikey index on a collection | ||
by using the ``MongoDB\Collection::createIndex()`` method and the same | ||
syntax that you use to create :ref:`single field indexes | ||
<php-single-field-index>`. | ||
|
||
Sample Data | ||
~~~~~~~~~~~ | ||
|
||
The examples in this guide use the ``movies`` collection in the | ||
``sample_mflix`` database from the :atlas:`Atlas sample datasets | ||
</sample-data>`. To learn how to create a free MongoDB Atlas cluster and | ||
load the sample datasets, see the :atlas:`Get Started with Atlas | ||
</getting-started>` guide. | ||
|
||
Create a Compound Index | ||
----------------------- | ||
|
||
Use the ``MongoDB\Collection::createIndex()`` method to create a | ||
compound index. The following example creates an index in ascending | ||
order on the ``title`` and ``year`` fields: | ||
|
||
.. literalinclude:: /includes/indexes/indexes.php | ||
:start-after: start-index-compound | ||
:end-before: end-index-compound | ||
:language: php | ||
:copyable: | ||
:dedent: | ||
|
||
The following is an example of a query that is covered by the index | ||
created in the preceding code example: | ||
|
||
.. io-code-block:: | ||
:copyable: true | ||
|
||
.. input:: /includes/indexes/indexes.php | ||
:start-after: start-compound-query | ||
:end-before: end-compound-query | ||
:language: php | ||
:dedent: | ||
|
||
.. output:: | ||
:visible: false | ||
|
||
{"_id":...,"title":"Before Sunrise",...,"year":1995,...} | ||
|
||
Additional Information | ||
---------------------- | ||
|
||
To learn more about compound indexes, see :manual:`Compound | ||
Indexes </core/index-compound>` in the {+mdb-server+} manual. | ||
|
||
To view runnable examples that demonstrate how to manage indexes, see | ||
:ref:`php-indexes`. | ||
|
||
API Documentation | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
To learn more about any of the methods discussed in this guide, see the following API | ||
documentation: | ||
|
||
- :phpmethod:`MongoDB\Collection::createIndex()` | ||
- :phpmethod:`MongoDB\Collection::findOne()` |
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
Oops, something went wrong.
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.
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.