Skip to content

Commit a6011d0

Browse files
committed
DOCSP-476: indexes on embedded fields can cover queries
1 parent 3d53bed commit a6011d0

File tree

2 files changed

+30
-29
lines changed

2 files changed

+30
-29
lines changed

source/core/query-optimization.txt

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,32 @@ For the specified index to cover the query, the projection document
123123
must explicitly specify ``_id: 0`` to exclude the ``_id`` field from
124124
the result since the index does not include the ``_id`` field.
125125

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+
126152
Performance
127153
~~~~~~~~~~~
128154

@@ -150,31 +176,6 @@ An index **cannot** cover a query if:
150176

151177
- .. include:: /includes/fact-geospatial-index-covered-query.rst
152178

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.
178179

179180
.. _covered-index-sharded-collection:
180181

@@ -194,9 +195,6 @@ method and review the :ref:`results <explain-output-covered-queries>`.
194195

195196
For more information see :ref:`indexes-measuring-use`.
196197

197-
.. [#index-embedded-document-fields] To index fields
198-
in embedded documents, use :term:`dot notation`.
199-
200198
.. class:: hidden
201199

202200
.. toctree::

source/release-notes/3.6.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,13 @@ MongoDB 3.6 includes the following enhancements:
169169
flush all in-memory data to disk, then verify the on-disk data. See
170170
also :ref:`3.6-validate-compatibility`.
171171

172+
173+
- An index can cover a query on fields within nested documents
174+
172175
- Added support for Diagnostics Capture (also known as :term:`FTDC`) in
173176
:program:`mongos`. In previous versions, the feature was available for
174177
:program:`mongod` only. See :ref:`param-ftdc`.
175-
178+
176179
.. note:: FTDC is enabled by default.
177180

178181
Changes Affecting Compatibility

0 commit comments

Comments
 (0)