Skip to content

Commit 6dc1b50

Browse files
committed
Update master
1 parent ca4d1bf commit 6dc1b50

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

draft/core/indexes.txt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ Compound Indexes
163163
MongoDB supports "compound indexes," where a single index structure
164164
holds references to multiple fields within a collection's
165165
documents. Consider the collection ``products`` that holds documents
166-
that resemble the following example document:
166+
that resemble the following example document:
167167

168168
.. code-block:: javascript
169169

@@ -184,21 +184,24 @@ specify a single compound index to support both of these queries:
184184

185185
db.products.ensureIndex( { "item": 1, "stock": 1 } )
186186

187+
Note that that order of the fields in a compound index is very important.
188+
Intuitively, the index above contains references to the documents sorted by
189+
``item``, and within each item, sorted by ``stock``.
187190
MongoDB will be able to use this index to support queries that select
188191
the ``item`` field as well as those queries that select the ``item``
189-
field **and** the ``stock`` field. However, these indexes will not
190-
support queries that select *only* the ``stock`` field.
192+
field **and** the ``stock`` field. However, this index will not
193+
be useful for queries that select *only* the ``stock`` field.
191194

192195
Ascending and Descending
193196
````````````````````````
194197

195198
Indexes store references to fields in either ascending or descending
196-
order. The order of keys often doesn't matter because MongoDB can
197-
transverse the index in either direction. However, in compound
198-
indexes, for some kinds of sort operations, it's useful to have the
199-
fields running in opposite order.
199+
order. For single-field indexes, the order of keys doesn't matter,
200+
because MongoDB can traverse the index in either direction. However, for
201+
compound indexes, it is occasionally useful to have the fields running in
202+
opposite order relative to each other.
200203

201-
To specify an index with an ascending order, use the following form:
204+
To specify an index with a descending order, use the following form:
202205

203206
.. code-block:: javascript
204207

@@ -213,6 +216,9 @@ following:
213216
db.products.ensureIndex( { "field0": 1, "field1": -1 } )
214217

215218
.. TODO understand the sort operations better.
219+
.. TODO Kevin's note: a good example here might be an index on
220+
{"username" : 1, "timestamp" : -1} which would be helpful for listing
221+
event history (most recent first) for all users (alphabetically).
216222

217223
.. _index-types-multikey:
218224

0 commit comments

Comments
 (0)