Skip to content

Commit 1741e88

Browse files
jeff-allen-mongokay-kim
authored andcommitted
DOCS-8848 - Updating partial index example
1 parent a12afc8 commit 1741e88

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

source/core/index-partial.txt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Query Coverage
5050
~~~~~~~~~~~~~~
5151

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

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

117117
.. code-block:: javascript
118118

119-
db.contacts.createIndex(
120-
{ name: 1 },
121-
{ partialFilterExpression: { name: { $exists: true } } }
119+
db.contacts.createIndex(
120+
{ name: 1 },
121+
{ partialFilterExpression: { name: { $exists: true } } }
122122
)
123123

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

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

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

145147
.. code-block:: javascript
146148

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

149-
However, the following query cannot use the index:
151+
However, the following query cannot use the index because it
152+
includes a null match on the ``email`` field, which is not permitted
153+
by the filter expression
154+
``{ email: { $exists: true } }``:
150155

151156
.. code-block:: javascript
152157

@@ -207,8 +212,8 @@ field is ``A``:
207212

208213
.. code-block:: javascript
209214

210-
db.restaurants.createIndex(
211-
{ borough: 1, cuisine: 1 },
215+
db.restaurants.createIndex(
216+
{ borough: 1, cuisine: 1 },
212217
{ partialFilterExpression: { 'rating.grade': { $eq: "A" } } }
213218
)
214219

0 commit comments

Comments
 (0)