Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
56be18e1
Commit
56be18e1
authored
Nov 09, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revise tutorial articles
parent
11b6a695
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
412 additions
and
476 deletions
+412
-476
commands.txt
docs/tutorial/commands.txt
+203
-266
crud.txt
docs/tutorial/crud.txt
+179
-179
indexes.txt
docs/tutorial/indexes.txt
+30
-31
No files found.
docs/tutorial/commands.txt
View file @
56be18e1
This diff is collapsed.
Click to expand it.
docs/tutorial/crud.txt
View file @
56be18e1
This diff is collapsed.
Click to expand it.
docs/tutorial/indexes.txt
View file @
56be18e1
...
@@ -4,12 +4,11 @@ Indexes
...
@@ -4,12 +4,11 @@ Indexes
.. default-domain:: mongodb
.. default-domain:: mongodb
Indexes support the efficient execution of queries in MongoDB. Without
Indexes support the efficient execution of queries in MongoDB. Without indexes,
indexes, MongoDB must perform a *collection scan*, i.e. scan every
MongoDB must perform a *collection scan*, i.e. scan every document in a
document in a collection, to select those documents that match the
collection, to select those documents that match the query statement. If an
query statement. If an appropriate index exists for a query,
appropriate index exists for a query, MongoDB can use the index to limit the
MongoDB can use the index to limit the number of documents it must
number of documents it must inspect.
inspect.
The PHP driver supports managing indexes through the
The PHP driver supports managing indexes through the
:phpclass:`MongoDB\\Collection` class, which implements MongoDB's
:phpclass:`MongoDB\\Collection` class, which implements MongoDB's
...
@@ -19,20 +18,20 @@ and `Enumerating Indexes
...
@@ -19,20 +18,20 @@ and `Enumerating Indexes
<https://github.com/mongodb/specifications/blob/master/source/enumerate-indexes.rst>`_
<https://github.com/mongodb/specifications/blob/master/source/enumerate-indexes.rst>`_
specifications.
specifications.
This document provides an introduction to creating, listing, and
This document provides an introduction to creating, listing, and
dropping
dropping indexes using the |php-library|. The MongoDB Manual'
s
indexes using the |php-library|. The MongoDB Manual's :manual:`Indexe
s
:manual:`Indexes Section </indexes>` provides more thorough
</indexes>` reference provides more thorough information about indexing in
information about indexing in
MongoDB.
MongoDB.
Create Indexes
Create Indexes
--------------
--------------
Create indexes with the :phpmethod:`MongoDB\\Collection::createIndex
`
Create indexes with the :phpmethod:`MongoDB\\Collection::createIndex
()` or
and :phpmethod:`MongoDB\\Collection::createIndexes` methods. Refer to
:phpmethod:`MongoDB\\Collection::createIndexes()` methods. Refer to the method
the method
reference for more details about each method.
reference for more details about each method.
The following example creates an ascending index on the ``state`` field
The following example creates an ascending index on the ``state`` field
using
using the :phpmethod:`createIndex
` method:
the :phpmethod:`createIndex() <MongoDB\\Collection::createIndex>
` method:
.. code-block:: php
.. code-block:: php
...
@@ -44,24 +43,23 @@ using the :phpmethod:`createIndex` method:
...
@@ -44,24 +43,23 @@ using the :phpmethod:`createIndex` method:
var_dump($result);
var_dump($result);
When you create an index, the method returns its name, which is
When you create an index, the method returns its name, which is
automatically
automatically generated from its specification. The above example would
generated from its specification. The above example would output something
output something
similar to::
similar to::
string(7) "state_1"
string(7) "state_1"
List Indexes
List Indexes
------------
------------
The :phpmethod:`MongoDB\\Collection::listIndexes` method provides
The :phpmethod:`MongoDB\\Collection::listIndexes()` method provides information
information about the indexes in a collection.
about the indexes in a collection. The
:phpmethod:`MongoDB\\Collection::listIndexes` method returns an
:phpmethod:`MongoDB\\Collection::listIndexes()` method returns an iterator of
iterator of ``MongoDB\Model\IndexInfo`` objects, which you can use to
:phpclass:`MongoDB\\Model\\IndexInfo` objects, which you can use to view
view information about each index. Refer to the method reference for
information about each index. Refer to the method reference for more details.
more details about each method.
The following example lists all indexes in the ``zips`` collection in
The following example lists all indexes in the ``zips`` collection in
the
the
``demo`` database:
``demo`` database:
.. code-block:: php
.. code-block:: php
...
@@ -105,9 +103,10 @@ The output would resemble::
...
@@ -105,9 +103,10 @@ The output would resemble::
Drop Indexes
Drop Indexes
------------
------------
The :phpmethod:`MongoDB\\Collection::dropIndex` lets you drop a single index while
The :phpmethod:`MongoDB\\Collection::dropIndex()` method lets you drop a single
:phpmethod:`MongoDB\\Collection::dropIndexes` drops all of the indexes on a collection.
index while :phpmethod:`MongoDB\\Collection::dropIndexes()` drops all of the
Refer to the method reference for more details about each method.
indexes on a collection. Refer to the method reference for more details about
each method.
The following example drops a single index by its name, ``state_1``:
The following example drops a single index by its name, ``state_1``:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment