@@ -50,7 +50,7 @@ Query Coverage
50
50
~~~~~~~~~~~~~~
51
51
52
52
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.
54
54
55
55
To use the partial index, a query must contain the filter expression
56
56
(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:
116
116
117
117
.. code-block:: javascript
118
118
119
- db.contacts.createIndex(
120
- { name: 1 },
121
- { partialFilterExpression: { name: { $exists: true } } }
119
+ db.contacts.createIndex(
120
+ { name: 1 },
121
+ { partialFilterExpression: { name: { $exists: true } } }
122
122
)
123
123
124
124
This partial index supports the same queries as a sparse index on the
@@ -137,16 +137,21 @@ filter expression is on the ``email`` field:
137
137
)
138
138
139
139
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.
142
142
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:
144
146
145
147
.. code-block:: javascript
146
148
147
149
db.contacts.find( { name: "xyz", email: { $regex: /\.org$/ } } )
148
150
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 } }``:
150
155
151
156
.. code-block:: javascript
152
157
@@ -207,8 +212,8 @@ field is ``A``:
207
212
208
213
.. code-block:: javascript
209
214
210
- db.restaurants.createIndex(
211
- { borough: 1, cuisine: 1 },
215
+ db.restaurants.createIndex(
216
+ { borough: 1, cuisine: 1 },
212
217
{ partialFilterExpression: { 'rating.grade': { $eq: "A" } } }
213
218
)
214
219
0 commit comments