Skip to content

DOCS-8848 - Updating partial index example #3236

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
merged 1 commit into from
Feb 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions source/core/index-partial.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Query Coverage
~~~~~~~~~~~~~~

MongoDB will not use the partial index for a query or sort operation if
using the index results in an incomplete result set.
using the index results in an incomplete result set.

To use the partial index, a query must contain the filter expression
(or a modified filter expression that specifies a subset of the filter
Expand Down Expand Up @@ -116,9 +116,9 @@ a partial index can implement the same behavior as a sparse index:

.. code-block:: javascript

db.contacts.createIndex(
{ name: 1 },
{ partialFilterExpression: { name: { $exists: true } } }
db.contacts.createIndex(
{ name: 1 },
{ partialFilterExpression: { name: { $exists: true } } }
)

This partial index supports the same queries as a sparse index on the
Expand All @@ -137,16 +137,21 @@ filter expression is on the ``email`` field:
)

For the query optimizer to choose this partial index, the query
predicate must include a non-null match on the ``email`` field as well
as a condition on the ``name`` field.
predicate must include a condition on the ``name`` field as well
as a *non-null* match on the ``email`` field.

For example, the following query can use the index:
For example, the following query can use the index because it includes
both a condition on the ``name`` field and a non-null match on the
``email`` field:

.. code-block:: javascript

db.contacts.find( { name: "xyz", email: { $regex: /\.org$/ } } )

However, the following query cannot use the index:
However, the following query cannot use the index because it
includes a null match on the ``email`` field, which is not permitted
by the filter expression
``{ email: { $exists: true } }``:

.. code-block:: javascript

Expand Down Expand Up @@ -207,8 +212,8 @@ field is ``A``:

.. code-block:: javascript

db.restaurants.createIndex(
{ borough: 1, cuisine: 1 },
db.restaurants.createIndex(
{ borough: 1, cuisine: 1 },
{ partialFilterExpression: { 'rating.grade': { $eq: "A" } } }
)

Expand Down