@@ -20,6 +20,9 @@ db.collection.ensureIndex()
20
20
characters. See the :method:`db.collection.getIndexes()` field
21
21
":data:`name`" for the names of existing indexes.
22
22
23
+ .. see:: The :doc:`/indexes` section of this manual for full
24
+ documentation of indexes and indexing in MongoDB.
25
+
23
26
Creates an index on the field specified, if that index does not
24
27
already exist. If the ``keys`` document specifies more than one
25
28
field, than :method:`db.collection.ensureIndex()` creates a :term:`compound
@@ -47,18 +50,37 @@ db.collection.ensureIndex()
47
50
The available options, possible values, and the default settings
48
51
are as follows:
49
52
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
62
84
63
85
:option Boolean background: Specify ``true`` to build the index
64
86
in the background so that building an
@@ -82,8 +104,10 @@ db.collection.ensureIndex()
82
104
:option Boolean dropDups: Specify ``true`` when creating a unique
83
105
index, on a field that *may* have
84
106
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.
87
111
88
112
:option Boolean sparse: If ``true``, the index only references
89
113
documents with the specified field. These
@@ -130,7 +154,6 @@ db.collection.ensureIndex()
130
154
:ref:`indexes-admin-stop-in-progress-build` for more
131
155
information.
132
156
133
-
134
157
.. [#] The default index version depends on the version of
135
158
:program:`mongod` running when creating the index. Before version
136
159
2.0, the this value was 0; versions 2.0 and later use version 1.
0 commit comments