@@ -123,6 +123,32 @@ For the specified index to cover the query, the projection document
123
123
must explicitly specify ``_id: 0`` to exclude the ``_id`` field from
124
124
the result since the index does not include the ``_id`` field.
125
125
126
+ .. versionchanged:: 3.6
127
+ An index can cover a query on fields within embedded documents.
128
+ [#index-embedded-document-fields]_
129
+
130
+ For example, consider a collection ``userdata`` with documents of the
131
+ following form:
132
+
133
+ .. code-block:: javascript
134
+
135
+ { _id: 1, user: { login: "tester" } }
136
+
137
+ The collection has the following index:
138
+
139
+ .. code-block:: none
140
+
141
+ { "user.login": 1 }
142
+
143
+ The ``{ "user.login": 1 }`` index will cover the query below:
144
+
145
+ .. code-block:: none
146
+
147
+ db.userdata.find( { "user.login": "tester" }, { "user.login": 1, _id: 0 } )
148
+
149
+ .. [#index-embedded-document-fields] To index fields
150
+ in embedded documents, use :term:`dot notation`.
151
+
126
152
Performance
127
153
~~~~~~~~~~~
128
154
@@ -150,31 +176,6 @@ An index **cannot** cover a query if:
150
176
151
177
- .. include:: /includes/fact-geospatial-index-covered-query.rst
152
178
153
- - any of the indexed fields in the query predicate or returned in the
154
- projection are fields in embedded documents.
155
- [#index-embedded-document-fields]_ For example, consider a collection
156
- ``users`` with documents of the following form:
157
-
158
- .. code-block:: javascript
159
-
160
- { _id: 1, user: { login: "tester" } }
161
-
162
- The collection has the following index:
163
-
164
- .. code-block:: none
165
-
166
- { "user.login": 1 }
167
-
168
- The ``{ "user.login": 1 }`` index will **not** cover the
169
- query below because this index is on a field in an embedded document:
170
-
171
- .. code-block:: none
172
-
173
- db.users.find( { "user.login": "tester" }, { "user.login": 1, _id: 0 } )
174
-
175
- This query can still use the ``{ "user.login": 1 }`` index to find
176
- matching documents but it will examine and fetch documents to satisfy the
177
- query.
178
179
179
180
.. _covered-index-sharded-collection:
180
181
@@ -194,9 +195,6 @@ method and review the :ref:`results <explain-output-covered-queries>`.
194
195
195
196
For more information see :ref:`indexes-measuring-use`.
196
197
197
- .. [#index-embedded-document-fields] To index fields
198
- in embedded documents, use :term:`dot notation`.
199
-
200
198
.. class:: hidden
201
199
202
200
.. toctree::
0 commit comments