@@ -40,6 +40,8 @@ of the ``people`` collection:
40
40
41
41
db.people.ensureIndex( { phone-number: 1 } )
42
42
43
+ TODO: you need ""s around phone-number, otherwise it's invalid JS (phone minus number).
44
+
43
45
To create a :ref:`compound index <index-type-compound>`, use an
44
46
operation that resembles the following prototype:
45
47
@@ -60,13 +62,17 @@ collection:
60
62
To build indexes for a :term:`replica set`, before version 2.2,
61
63
see :ref:`index-building-replica-sets`.
62
64
65
+ TODO: I don't think anything changed about replica set index builds for 2.2...
66
+
63
67
.. [#ensure] As the name suggests, :func:`ensureIndex() <db.collection.ensureIndex()>`
64
68
only creates an index if an index of the same specification does
65
69
not already exist.
66
70
67
71
Sparse
68
72
``````
69
73
74
+ TODO: Sparse? Maybe "Types of Indexes->Sparse"?
75
+
70
76
To create a :ref:`sparse index <index-type-sparse>` on a field, use an
71
77
operation that resembles the following prototype:
72
78
@@ -87,6 +93,12 @@ without the ``twitter_name`` field.
87
93
88
94
MongoDB cannot create sparse compound indexes.
89
95
96
+ TODO: is this true? I thought that it could.
97
+
98
+ TODO: Is there more doc on spare indexes somewhere? Seems like this is missing
99
+ some info like getting different results back when the index is used, null
100
+ counts as existing, etc.
101
+
90
102
Unique
91
103
``````
92
104
@@ -105,10 +117,14 @@ records for the same legal entity:
105
117
106
118
db.accounts.ensureIndex( { tax-id: 1 }, { unique: true } )
107
119
120
+ TODO: tax-id should be in ""s.
121
+
108
122
The :ref:`_id index <index-type-primary>` is a unique index. In some
109
123
situations you may want to use the ``_id`` field for these primary
110
124
data rather than using a unique index on another field.
111
125
126
+ TODO: "for these primary data"?
127
+
112
128
In many situations you will want to combine the ``unique`` constraint
113
129
with the ``sparse`` option. When MongoDB indexes a field, if a
114
130
document does not have a value for a field, the index entry for that
@@ -141,6 +157,8 @@ as in the following example:
141
157
142
158
db.accounts.dropIndex( { tax-id: 1 } )
143
159
160
+ TODO: ""s!
161
+
144
162
This will remove the index on the ``tax-id`` field in the ``accounts``
145
163
collection. The shell provides the following document after completing
146
164
the operation:
@@ -203,6 +221,12 @@ for this operation.
203
221
To rebuild indexes for a :term:`replica set`, before version 2.2,
204
222
see :ref:`index-rebuilding-replica-sets`.
205
223
224
+ TODO: again, this probably isn't different in 2.2
225
+
226
+ TODO: one thing that I would appreciate you mentioning is that some drivers may
227
+ create indexes like {a : NumberLong(1)} _which is fine_ and doesn't break
228
+ anything so stop complaining about it.
229
+
206
230
Special Creation Options
207
231
~~~~~~~~~~~~~~~~~~~~~~~~
208
232
@@ -211,6 +235,8 @@ Special Creation Options
211
235
TTL collections use a special ``expire`` index option. See
212
236
:doc:`/tutorial/expire-data` for more information.
213
237
238
+ TODO: Are 2d indexes getting a mention?
239
+
214
240
Background
215
241
``````````
216
242
@@ -222,11 +248,25 @@ prototype invocation of :func:`db.collection.ensureIndex()`:
222
248
223
249
db.collection.ensureIndex( { a: 1 }, { background: true } )
224
250
251
+ TODO: what does it mean to build an index in the background? You might want to
252
+ mention:
253
+ * performance implications
254
+ * that this type of index build can be killed
255
+ * that this blocks the connection you sent the ensureindex on, but ops from
256
+ other connections can proceed in
257
+ * that indexes are created on the foreground on secondaries in 2.0,
258
+ which blocks replication & slave reads. In 2.2, it does not block reads (but
259
+ still blocks repl).
260
+
225
261
Drop Duplicates
226
262
```````````````
227
263
228
264
To force the creation of a :ref:`unique index <index-type-unique>`
229
- index, you can use the ``dropDups`` option. This will force MongoDB to
265
+ index
266
+
267
+ TODO: " on a collection with duplicate values in the field to be indexed "
268
+
269
+ you can use the ``dropDups`` option. This will force MongoDB to
230
270
create a *unique* index by deleting documents with duplicate values
231
271
when building the index. Consider the following prototype invocation
232
272
of :func:`db.collection.ensureIndex()`:
@@ -243,12 +283,15 @@ See the full documentation of :ref:`duplicate dropping
243
283
Specifying ``{ dropDups: true }`` will delete data from your
244
284
database. Use with extreme caution.
245
285
286
+ TODO: I'd say it "may" delete data from your DB, not like it's going to go all
287
+ Shermanesque on your data.
288
+
246
289
.. _index-building-replica-sets:
247
290
248
291
Building Indexes on Replica Sets
249
292
--------------------------------
250
293
251
- .. versionchanged:: 2.2
294
+ .. versionchanged:: 2.2
252
295
Index rebuilding operations on :term:`secondary` members of
253
296
:term:`replica sets <replica set>` now run as normal background
254
297
index operations. Run :func:`ensureIndex()
@@ -257,20 +300,30 @@ Building Indexes on Replica Sets
257
300
the following operation to isolate and control the impact of
258
301
indexing building operations on a set as a whole.
259
302
303
+ TODO: I think there needs to be a huge mention that this still blocks
304
+ replication, so the procedure below is recommended.
305
+
260
306
.. admonition:: For Version 1.8 and 2.0
261
307
262
308
:ref:`Background index creation operations
263
309
<index-creation-background>` became *foreground* indexing
264
310
operations on :term:`secondary` members of replica sets. These
265
311
foreground operations will block all replication on the
266
- secondaries, and can impact performance of the entire set. To build
312
+ secondaries,
313
+
314
+ TODO: and don't allow any reads to go through.
315
+
316
+ and can impact performance of the entire set. To build
267
317
indexes with minimal impact on a replica set, use the following
268
318
procedure for all non-trivial index builds:
269
319
270
320
#. Stop the :program:`mongod` process on one secondary. Restart the
271
- :program:`mongod` process *without* the :option:`--replSet <mongod --replSet>`
321
+ :program:`mongod` process *without* the :option:`--replSet <mongod --replSet>`
272
322
option. This instance is now in "standalone" mode.
273
323
324
+ TODO: generally we recommend running it on a different port, too, so that apps
325
+ & other servers in the set don't try to contact it.
326
+
274
327
#. Create the new index or rebuild the index on this :program:`mongod`
275
328
instance.
276
329
@@ -287,7 +340,7 @@ Building Indexes on Replica Sets
287
340
288
341
Ensure that your :ref:`oplog` is large enough to permit the
289
342
indexing or re-indexing operation to complete without falling
290
- too far behind to catch up. See the ":ref:`replica-set-oplog-sizing`"
343
+ too far behind to catch up. See the ":ref:`replica-set-oplog-sizing`"
291
344
documentation for additional information.
292
345
293
346
.. note::
@@ -301,6 +354,9 @@ Building Indexes on Replica Sets
301
354
For the best results, always create indexes *before* you begin
302
355
inserting data into a collection.
303
356
357
+ TODO: well, sort of. That'll build the indexes fast, but make the inserts
358
+ slower. Overall, it's faster to insert data, then build indexes.
359
+
304
360
Measuring Index Use
305
361
-------------------
306
362
@@ -318,7 +374,12 @@ following tools:
318
374
- :func:`cursor.hint()`
319
375
320
376
Append the :func:`hint() <cursor.hint()>` to any cursor (e.g.
321
- query) with the name of an index as the argument to *force* MongoDB
377
+ query) with the name
378
+
379
+ TODO: this isn't "the name of an index." I'd say just "with the index." The
380
+ name of an index is a string like "zipcode_1".
381
+
382
+ of an index as the argument to *force* MongoDB
322
383
to use a specific index to fulfill the query. Consider the following
323
384
example:
324
385
@@ -331,8 +392,13 @@ following tools:
331
392
<cursor.explain()>` in conjunction with each other to compare the
332
393
effectiveness of a specific index.
333
394
395
+ TODO: mention $natural to force no index usage?
396
+
334
397
- :status:`indexCounters`
335
398
336
399
Use the :status:`indexCounters` data in the output of
337
400
:dbcommand:`serverStatus` for insight into database-wise index
338
401
utilization.
402
+
403
+ TODO: I'd like to see this also cover how to track how far an index build has
404
+ gotten and how to kill an index build.
0 commit comments