Skip to content

DOCS-1492 db.collection.ensureIndex #1096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/includes/ref-toc-method-collection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ name: ":method:`db.collection.dropIndexes()`"
file: /reference/method/db.collection.dropIndexes
description: "Removes all indexes on a collection."
---
name: ":method:`db.collection.ensureIndex`"
name: ":method:`db.collection.ensureIndex()`"
file: /reference/method/db.collection.ensureIndex
description: "Creates an index if it does not currently exist. If the index exists :method:`~db.collection.ensureIndex()` does nothing."
---
Expand Down
157 changes: 157 additions & 0 deletions source/reference/method/db.collection.ensureIndex-options-param.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
object:
name: db.collection.ensureIndex()
type: method
field:
optional: true
type: param
name: background
type: Boolean
position: 1
description: |
Builds the index in the background so that building an index does
*not* block other database activities. Specify ``true`` to build in
the background. The default value is ``false``.
---
object:
name: db.collection.ensureIndex()
type: method
field:
optional: true
type: param
name: unique
type: Boolean
position: 2
description: |
Creates a unique index so that the collection will not accept
insertion of documents where the index key or keys match an existing
value in the index. Specify ``true`` to create a unique index. The
default value is ``false``. This option applies only to ascending/descending
indexes.
---
object:
name: db.collection.ensureIndex()
type: method
field:
optional: true
type: param
name: name
type: string
position: 3
description: |
The name of the index. If unspecified, MongoDB generates an index name
by concatenating the names of the indexed fields and the sort order.
---
object:
name: db.collection.ensureIndex()
type: method
field:
optional: true
type: param
name: dropDups
type: Boolean
position: 4
description: |
Creates a unique index on a field that *may* have duplicates. MongoDB
indexes only the first occurrence of a key and **removes** all
documents from the collection that contain subsequent occurrences of
that key. Specify ``true`` to create unique index. The default value
is ``false``. This option applies only to scalar indexes.
---
object:
name: db.collection.ensureIndex()
type: method
field:
optional: true
type: param
name: sparse
type: Boolean
position: 5
description: |
If ``true``, the index only references documents with the specified
field. These indexes use less space but behave differently in some
situations (particularly sorts). The default value is ``false``. This
applies only to ascending/descending indexes.
---
object:
name: db.collection.ensureIndex()
type: method
field:
optional: true
type: param
name: expireAfterSeconds
type: integer
position: 6
description: |
Specifies a value, in seconds, as a :term:`TTL` to control how long
MongoDB retains documents in this collection. See
:doc:`/tutorial/expire-data` for more information on this
functionality. This applies only to :term:`TTL` indexes.
---
object:
name: db.collection.ensureIndex()
type: method
field:
optional: true
type: param
name: v
type: index version
position: 7
description: |
The index version number. The default index version depends on the
version of :program:`mongod` running when creating the index. Before
version 2.0, the this value was 0; versions 2.0 and later use version
1, which provides a smaller and faster index format. Specify a
different index version *only* in unusual situations.
---
object:
name: db.collection.ensureIndex()
type: method
field:
optional: true
type: param
name: weights
type: document
position: 8
description: |
For ``text`` indexes, the significance of the field relative to the
other indexed fields. The document contains field and weight pairs.
The weight is a number ranging from 1 to 99,999 and denotes the
significance of the field relative to the other indexed fields in
terms of the score. You can specify weights for some or all the
indexed fields. See :doc:`/tutorial/control-results-of-text-search` to
adjust the scores. The default value is ``1``. This applies to
``text`` indexes only.
---
object:
name: db.collection.ensureIndex()
type: method
field:
optional: true
type: param
name: default_language
type: string
position: 9
description: |
For a ``text`` index, the language that determines the list of stop
words and the rules for the stemmer and tokenizer. See
:ref:`text-search-languages` for the available languages and
:doc:`/tutorial/specify-language-for-text-index` for more information
and examples. The default value is ``english``. This applies to
``text`` indexes only.
---
object:
name: db.collection.ensureIndex()
type: method
field:
optional: true
type: param
name: language_override
type: string
position: 10
description: |
For a ``text`` index, specify the name of the field in the document
that contains, for that document, the language to override the default
language. See
:doc:`/tutorial/create-text-index-on-multi-language-collection`. The
default value is ``language``.
...
32 changes: 32 additions & 0 deletions source/reference/method/db.collection.ensureIndex-param.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
object:
name: db.collection.ensureIndex()
type: method
field:
optional: false
type: param
name: keys
type: document
position: 1
description: |
For ascending/descending indexes, a :ref:`document
<document-index-specification>` that contains pairs with the
name of the field or fields to index and order of the index. A
``1`` specifies ascending and a ``-1`` specifies descending.
MongoDB supports several different index types including
:ref:`text <index-feature-text>`, :doc:`geospatial
</applications/geospatial-indexes>`, and :ref:`hashed
<index-type-hashed>` indexes.
---
object:
name: db.collection.ensureIndex()
type: method
field:
optional: true
type: param
name: options
type: document
position: 2
description: |
A document that controls the creation of the index. The document
contains a set of options, as described in the next table.
...
Loading