Skip to content

Commit ffb2af1

Browse files
author
Sam Kleinman
committed
DOCS-790 updates and clarification for the ensureIndex reference page
1 parent 0517797 commit ffb2af1

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

source/reference/method/db.collection.ensureIndex.txt

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ db.collection.ensureIndex()
2020
characters. See the :method:`db.collection.getIndexes()` field
2121
":data:`name`" for the names of existing indexes.
2222

23+
.. see:: The :doc:`/indexes` section of this manual for full
24+
documentation of indexes and indexing in MongoDB.
25+
2326
Creates an index on the field specified, if that index does not
2427
already exist. If the ``keys`` document specifies more than one
2528
field, than :method:`db.collection.ensureIndex()` creates a :term:`compound
@@ -47,18 +50,37 @@ db.collection.ensureIndex()
4750
The available options, possible values, and the default settings
4851
are as follows:
4952

50-
==================== ================= =========
51-
Option Value Default
52-
==================== ================= =========
53-
background true or false false
54-
unique true or false false
55-
name string none
56-
cache true or false true
57-
dropDups true or false false
58-
sparse true or false false
59-
expireAfterSeconds integer none
60-
v index version. 1 [#]_
61-
==================== ================= =========
53+
.. list-table::
54+
:header-rows: 1
55+
56+
* - **Option**
57+
- **Plugin**
58+
- **Default**
59+
60+
* - background
61+
- ``true`` or ``false``
62+
- ``false``
63+
* - unique
64+
- ``true`` or ``false``
65+
- ``false``
66+
* - name
67+
- string
68+
- none
69+
* - cache
70+
- ``true`` or ``false``
71+
- ``true``
72+
* - dropDups
73+
- ``true`` or ``false``
74+
- ``false``
75+
* - sparse
76+
- ``true`` or ``false``
77+
- ``false``
78+
* - expireAfterSeconds
79+
- integer
80+
- none
81+
* - v
82+
- index version
83+
- 1
6284

6385
:option Boolean background: Specify ``true`` to build the index
6486
in the background so that building an
@@ -82,8 +104,10 @@ db.collection.ensureIndex()
82104
:option Boolean dropDups: Specify ``true`` when creating a unique
83105
index, on a field that *may* have
84106
duplicate to index only the first
85-
occurrence of a key, and ignore
86-
subsequent occurrences of that key.
107+
occurrence of a key, and **remove** all
108+
documents from the collection that
109+
contain subsequent occurrences of that
110+
key.
87111

88112
:option Boolean sparse: If ``true``, the index only references
89113
documents with the specified field. These
@@ -130,7 +154,6 @@ db.collection.ensureIndex()
130154
:ref:`indexes-admin-stop-in-progress-build` for more
131155
information.
132156

133-
134157
.. [#] The default index version depends on the version of
135158
:program:`mongod` running when creating the index. Before version
136159
2.0, the this value was 0; versions 2.0 and later use version 1.

0 commit comments

Comments
 (0)