From b634bbede5a16ef6ac14fb51e0cd0f02dc0c9ac0 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Tue, 20 Nov 2012 15:11:22 -0500 Subject: [PATCH 01/10] adding warning about terminating current operations --- source/includes/warning-terminating-operations.rst | 5 +++++ source/reference/method/db.currentOp.txt | 2 ++ source/reference/method/db.killOp.txt | 2 ++ 3 files changed, 9 insertions(+) create mode 100644 source/includes/warning-terminating-operations.rst diff --git a/source/includes/warning-terminating-operations.rst b/source/includes/warning-terminating-operations.rst new file mode 100644 index 00000000000..4aa44658c0e --- /dev/null +++ b/source/includes/warning-terminating-operations.rst @@ -0,0 +1,5 @@ +.. warning:: + + Terminate running operations with extreme caution. Only use + :method:`db.killOp()` to terminate operations initiated by clients + and *do not* terminate internal database operations. diff --git a/source/reference/method/db.currentOp.txt b/source/reference/method/db.currentOp.txt index a380a64a864..c8d7975c934 100644 --- a/source/reference/method/db.currentOp.txt +++ b/source/reference/method/db.currentOp.txt @@ -21,3 +21,5 @@ db.currentOp() identify specific types of operations: .. include:: /includes/example-filter-current-op.rst + + .. warning:: /includes/warning-terminating-operations.rst diff --git a/source/reference/method/db.killOp.txt b/source/reference/method/db.killOp.txt index f4ec8719632..04857cbf6bc 100644 --- a/source/reference/method/db.killOp.txt +++ b/source/reference/method/db.killOp.txt @@ -12,3 +12,5 @@ db.killOp() to find operations and their corresponding ids. See :doc:`/reference/current-op` for full documentation of the output of :method:`db.currentOp()`. + + .. include:: /includes/warning-terminating-operations.rst From 611321e68fe2911df50748868bb6726cdf6827ed Mon Sep 17 00:00:00 2001 From: markofu Date: Wed, 21 Nov 2012 19:19:37 +0000 Subject: [PATCH 02/10] Modified Fedora tutorial --- ...godb-on-red-hat-centos-or-fedora-linux.txt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux.txt b/source/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux.txt index f6ddde28863..43650a3cfbe 100644 --- a/source/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux.txt +++ b/source/tutorial/install-mongodb-on-red-hat-centos-or-fedora-linux.txt @@ -143,6 +143,15 @@ run using the ``mongod`` user account. Control MongoDB --------------- +Warning +~~~~~~~~~~~~~ + +Since Fedora15, Fedora has moved to ``systemd`` and the control +scripts (from the 10gen repo) do not work. There is currently an +open SERVER ticket for this fix: + + - :link:`https://jira.mongodb.org/browse/SERVER-7285` + Start MongoDB ~~~~~~~~~~~~~ @@ -188,6 +197,8 @@ Follow the state of this process by watching the output in the ``/var/log/mongo/mongod.log`` file to watch for errors or important messages from the server. +You can restart the :program:`mongod` process by issuing the following +command (as root, or with ``sudo``): Control :program:`mongos` ~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -198,6 +209,15 @@ systems where :program:`mongod` runs. You can use the ``mongodb`` script referenced above to derive your own :program:`mongos` control script. +SELinux +~~~~~~~~~~~~~~~ + +SELinux prevents MongoDB from starting on Fedora. There are two +options: + + - enable access to the relevant ports (e.g. 27017) on SELinux + - disable SELinux (will require a reboot) + Using MongoDB ------------- From 59ced87d0c8a2f5791f3e4116c09f0fc3e162eb9 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Wed, 21 Nov 2012 14:29:06 -0500 Subject: [PATCH 03/10] minor typo fix --- source/core/sharding.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/core/sharding.txt b/source/core/sharding.txt index d85b157698c..034c45ece0c 100644 --- a/source/core/sharding.txt +++ b/source/core/sharding.txt @@ -160,7 +160,7 @@ A :term:`sharded cluster` has the following components: in a sharded cluster via the :program:`mongos` instances as below. If you connect directly to a :program:`mongod` in a sharded cluster you will see its fraction of cluster's data. The data on any - given shard may be somewhat random: MongoDB provides no grantee + given shard may be somewhat random: MongoDB provides no guarantee that any two contiguous chunks will reside on a single shard. - One or more :program:`mongos` instances. From 5ca6557909f90ba89a8ad65ed4905fa76f012e88 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Wed, 21 Nov 2012 14:33:22 -0500 Subject: [PATCH 04/10] DOCS-758 correction about lock scope in fsynclock and unlock --- source/reference/method/db.fsyncLock.txt | 9 +++++---- source/reference/method/db.fsyncUnlock.txt | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/source/reference/method/db.fsyncLock.txt b/source/reference/method/db.fsyncLock.txt index dd42c0c9413..55e7fffd455 100644 --- a/source/reference/method/db.fsyncLock.txt +++ b/source/reference/method/db.fsyncLock.txt @@ -6,10 +6,11 @@ db.fsyncLock() .. method:: db.fsyncLock() - Forces the database to flush all write operations to the disk and - locks the database to prevent additional writes until the user - releases the lock with the :method:`db.fsyncUnlock()` - command. :method:`db.fsyncLock()` is an administrative command. + Forces the :program:`mongod` to flush pending all write operations + to the disk and locks the *entire* :program:`mongod` instance to + prevent additional writes until the user releases the lock with the + :method:`db.fsyncUnlock()` command. :method:`db.fsyncLock()` is an + administrative command. This command provides a simple wrapper around a :dbcommand:`fsync` database command with the following diff --git a/source/reference/method/db.fsyncUnlock.txt b/source/reference/method/db.fsyncUnlock.txt index 8a16e450bd8..f428f2bd670 100644 --- a/source/reference/method/db.fsyncUnlock.txt +++ b/source/reference/method/db.fsyncUnlock.txt @@ -6,7 +6,7 @@ db.fsyncUnlock() .. method:: db.fsyncUnlock() - Unlocks a database server to allow writes and reverses the + Unlocks a :program:`mongod` instance to allow writes and reverses the operation of a :method:`db.fsyncLock()` operation. Typically you will use :method:`db.fsyncUnlock()` following a database :doc:`backup operation `. From c300a8432609eff0624446195312ab5c5922ba55 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Sat, 24 Nov 2012 16:35:12 -0500 Subject: [PATCH 05/10] reprhasing of command introduction per reqest from @erh --- source/reference/commands.txt | 45 ++++++++++++++++------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/source/reference/commands.txt b/source/reference/commands.txt index 451d9f49f48..b3f21fe70b1 100644 --- a/source/reference/commands.txt +++ b/source/reference/commands.txt @@ -25,47 +25,41 @@ specify the :dbcommand:`isMaster` command using the following { isMaster: 1 } -To execute this command, you send this document as a query on the -special :term:`$cmd` collection: - -.. code-block:: javascript - - db.$cmd.findOne( {isMaster: 1} ) - -The JavaScript shell (i.e. :program:`mongo`,) provides a helper method for -running commands. The following commands are equivalent to the above -command: +The :program:`mongo` shell provides a helper method for running +commands called :method:`db.runCommand()`. The following operation in +:program:`mongo` runs the above command: .. code-block:: javascript db.runCommand( { isMaster: 1 } ) -Many commands have their own shell helpers: +Many :doc:`drivers ` provide an equivalent for +the :method:`db.runCommand()` method. Internally, running commands +with :method:`db.runCommand()` is equivelent to a special query +against the :term:`$Cmdr` collection. -.. code-block:: javascript - - db.isMaster(); +Many common commands have their own shell helpers or wrappers in the +:program:`mongo` shell and drivers, such as the +:method:`db.isMaster()` method in the :program:`mongo` JavaScript +shell. .. _admin-command: You must run some commands on the :term:`admin database`. Normally, -these operations resemble the followings: +these operations resemble the followings: .. code-block:: javascript use admin db.runCommand( {buildInfo: 1} ) -However, there's also a command helper that automatically switches to -this database: +However, there's also a command helper that automatically runs the +command in the context of the ``admin`` database: .. code-block:: javascript db._adminCommand( {buildInfo: 1} ) -The ``_adminCommand`` helper is shorthand for -``db.getSisterDB("admin").runCommand();``. - All commands return, at minimum, a document with an ``ok`` field indicating whether the command has succeeded: @@ -73,11 +67,12 @@ indicating whether the command has succeeded: { 'ok': 1 } -If the command fails, the value of ``ok`` will be 0. +Failed commands return the ``ok`` field with a value of ``0``. -In the command descriptions below, we provide the document template -for each command. In some cases, we also show the relevant :program:`mongo` -shell helpers. +All of the following command descriptions, provide a document template +or prototype for each command. Some command documentation also +includes the relevant :program:`mongo` shell helpers. See +:doc:`/reference/command` for a list of all comamnds. User Commands ------------- @@ -253,7 +248,7 @@ Diagnostic Commands .. include:: command/buildInfo.txt :start-after: mongodb - + .. include:: command/dbStats.txt :start-after: mongodb From a881400f97bb4a496fa5bb9408e4ae1ee0127d2a Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Mon, 26 Nov 2012 08:15:21 -0500 Subject: [PATCH 06/10] build: refactor makefile generator library for better clarity and testing --- bin/makefile_builder.py | 151 ++++++++++++++++++++++++++++------------ 1 file changed, 107 insertions(+), 44 deletions(-) diff --git a/bin/makefile_builder.py b/bin/makefile_builder.py index 203092f6aeb..c0058128182 100644 --- a/bin/makefile_builder.py +++ b/bin/makefile_builder.py @@ -1,4 +1,7 @@ +#!/usr/bin/python + # Copyright 2012 10gen, Inc. +# Author: Sam Kleinman (tychoish) # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,25 +15,98 @@ # See the License for the specific language governing permissions and # limitations under the License. -class MakefileBuilder(object): - def __init__(self, makefile=None): - self.builder = { '_all' : [] } - if makefile is not None and type(makefile) is list: - self.makefile = makefile +def print_output(list): + for line in list: + print(line) + +def write_file(list, filename): + with open(filename, 'w') as f: + for line in list: + f.write(line + '\n') + + +class BuildFileError(Exception): + def __init__(self, msg=None): + self.msg = msg + + def __str__(self): + if self.msg is None: + return "Error in handling BuildFile." else: - self.makefile = self.builder['_all'] = [] + return "Error: " + self.msg - def add_to_builder(self, data, block): - if block is '_all': +class BuildFile(object): + def __init__(self, buildfile=None): + self.builder = { '_all' : [] } + self.buildfile = self.builder['_all'] + + if buildfile is None: pass + elif type(buildfile) is list: + for line in buildfile: + if type(line) is list: + raise BuildFileError('Cannot instantiate BuildFile with nested list.') + break + else: + self.builder['_all'].append(line) else: - self.makefile.append(data) + raise BuildFileError('Instantiated BuildFile object with malformed argument.') - if block in self.builder: - self.builder[block].append(data) + # the following method is used internally to constrcd uct and + # maintain the internal representation of the buildfile. + + def _add_to_builder(self, data, block): + if type(data) is not str: + raise BuildFileError('Added malformed data to BuildFile.') else: - self.builder[block] = [data] + if block is '_all': + pass + else: + self.buildfile.append(data) + + if block in self.builder: + self.builder[block].append(data) + else: + self.builder[block] = [data] + + # The following methods produce output for public use. + + def get_block(self, block='_all'): + return self.builder[block] + + def print_content(self, block_order=['_all']): + output = [] + + for block in block_order: + output.append(self.builder[block]) + + output = [item for sublist in output for item in sublist] + print_output(output) + + def print_block(self, block='all'): + print_output(self.builder[block]) + + def write(self, filename, block_order=['_all']): + output = [] + + for block in block_order: + output.append(self.builder[block]) + + output = [item for sublist in output for item in sublist] + write_file(output, filename) + + def write_block(self, filename, block='_all'): + write_file(self.builder[block], filename) + + +class MakefileBuilder(BuildFile): + def __init__(self, makefile=None): + super(MakefileBuilder, self).__init__(makefile) + self.makefile = self.buildfile + + # The following two methods allow more direct interaction with the + # internal representation of the makefile than the other methods. def block(self, block): if block in self.builder: @@ -40,56 +116,43 @@ def block(self, block): self.section_break(block, block) def raw(self, lines, block='_all'): - self.add_to_builder(lines, block) + self._add_to_builder(lines, block) + + # The following methods constitute the 'public' interface for + # building makefile. def section_break(self, name, block='_all'): - self.add_to_builder('\n\n########## ' + name + ' ##########\n', block) + self._add_to_builder('\n\n########## ' + name + ' ##########', block) def comment(self, comment, block='_all'): - self.add_to_builder('\n# ' + comment + '\n', block) + self._add_to_builder('\n# ' + comment, block) def newline(self, n=1, block='_all'): for i in range(n): - self.add_to_builder('\n', block) + self._add_to_builder('\n', block) def target(self, target, dependency=None, block='_all'): - if dependency is None: - self.add_to_builder(target + ':' + '\n', block) - else: - self.add_to_builder(target + ':' + dependency + '\n', block) - + if dependency is None: + self._add_to_builder(target + ':', block) + else: + self._add_to_builder(target + ':' + dependency, block) + def var(self, variable, value, block='_all'): - self.add_to_builder(variable + ' = ' + value + '\n', block) + self._add_to_builder(variable + ' = ' + value, block) def append_var(self, variable, value, block='_all'): - self.add_to_builder(variable + ' += ' + value + '\n', block) + self._add_to_builder(variable + ' += ' + value, block) def job(self, job, display=False, block='_all'): if display is True: - o = '\t' + job + '\n' + o = '\t' + job else: - o = '\t@' + job + '\n' + o = '\t@' + job - self.add_to_builder(o, block) + self._add_to_builder(o, block) def message(self, message, block='_all'): - self.add_to_builder('\t@echo ' + message + '\n', block) + m = 'echo ' + message + self.job(job=m, display=False, block=block) msg = message - - def print_content(self, block_order=['_all']): - o = [] - for block in block_order: - o.append(self.builder[block]) - o = [item for sublist in o for item in sublist] - for line in o: - print(line.rstrip()) - - def write(self, filename, block_order=['_all']): - o = [] - for block in block_order: - o.append(self.builder[block]) - o = [item for sublist in o for item in sublist] - with open(filename, 'w') as f: - for line in o: - f.write(line) From f95db85bdaf28c41b717b7c03e635f0a8a78a116 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Mon, 26 Nov 2012 08:16:49 -0500 Subject: [PATCH 07/10] minor: correcting cross reference error --- source/reference/commands.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/reference/commands.txt b/source/reference/commands.txt index b3f21fe70b1..d7c328799c4 100644 --- a/source/reference/commands.txt +++ b/source/reference/commands.txt @@ -36,7 +36,7 @@ commands called :method:`db.runCommand()`. The following operation in Many :doc:`drivers ` provide an equivalent for the :method:`db.runCommand()` method. Internally, running commands with :method:`db.runCommand()` is equivelent to a special query -against the :term:`$Cmdr` collection. +against the :term:`$cmd` collection. Many common commands have their own shell helpers or wrappers in the :program:`mongo` shell and drivers, such as the From 474634816d763bf196873d6e0ec2e735b860054d Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Mon, 26 Nov 2012 12:11:41 -0500 Subject: [PATCH 08/10] DOCS-792 correcting issue about rs.conf array indexes. --- source/administration/replica-sets.txt | 18 +++++++++++------- source/includes/note-rs-conf-array-index.rst | 10 ++++++++++ source/reference/replica-configuration.txt | 6 ++++-- 3 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 source/includes/note-rs-conf-array-index.rst diff --git a/source/administration/replica-sets.txt b/source/administration/replica-sets.txt index ce24688c406..0e6431c6b47 100644 --- a/source/administration/replica-sets.txt +++ b/source/administration/replica-sets.txt @@ -87,10 +87,11 @@ To configure a member as secondary-only, set its situation. For more information on priority levels, see :ref:`replica-set-node-priority`. +.. include:: /includes/note-rs-conf-array-index.rst + As an example of modifying member priorities, assume a four-member -replica set with member ``_id`` values of: ``0``, ``1``, ``2``, and -``3``. Use the following sequence of operations in the :program:`mongo` -shell to modify member priorities: +replica set. Use the following sequence of operations in the +:program:`mongo` shell to modify member priorities: .. code-block:: javascript @@ -101,9 +102,9 @@ shell to modify member priorities: cfg.members[3].priority = 2 rs.reconfig(cfg) -This sets the following: +This configures the set, with the following priority settings: -- Member ``0`` to a priority of ``0`` so that it can never become :term:`primary`. +- The first (i.e. )Member ``0`` to a priority of ``0`` so that it can never become :term:`primary`. - Member ``1`` to a priority of ``0.5``, which makes it less likely to become primary than other members but doesn't prohibit the @@ -466,11 +467,14 @@ the :program:`mongo` shell: The first operation uses :method:`rs.conf()` to set the local variable ``cfg`` to the contents of the current replica set configuration, which is a :term:`document`. The next three operations change the -:data:`members[n].priority` value in the ``cfg`` document for -:data:`members[n]._id` of ``0``, ``1``, or ``2``. The final operation +:data:`members[n].priority` value in the ``cfg`` document for the +first three members configured in the :data:`members +` array. The final operation calls :method:`rs.reconfig()` with the argument of ``cfg`` to initialize the new configuration. +.. include:: /includes/note-rs-conf-array-index.rst + If a member has :data:`members[n].priority` set to ``0``, it is ineligible to become :term:`primary` and will not seek election. :ref:`Hidden members `, diff --git a/source/includes/note-rs-conf-array-index.rst b/source/includes/note-rs-conf-array-index.rst new file mode 100644 index 00000000000..ff2ec090d58 --- /dev/null +++ b/source/includes/note-rs-conf-array-index.rst @@ -0,0 +1,10 @@ +.. note:: + + When updating the replica configuration object, address all members + of the set using the index value in the array. The array index + begins with ``0``. Do not confuse this index value with the value + of the :data:`_id ` array. + + The :data:`_id : @@ -322,8 +324,8 @@ operation: This operation begins by saving the current replica set configuration to the local variable ``cfg`` using the :method:`rs.conf()` method. Then it adds priority values to the - :term:`document` where the :data:`members[n]._id` field has a value - of ``0``, ``1``, or ``2``. Finally, it calls the + ``cfg`` :term:`document` where for the first three sub-documents in + the :data:`members ` array. Finally, it calls the :method:`rs.reconfig()` method with the argument of ``cfg`` to initialize this new configuration. The replica set configuration after this operation will resemble the following: From 0517797bef710c9b6cf25bfc131fbd3b243ee8a3 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Mon, 26 Nov 2012 14:48:58 -0500 Subject: [PATCH 09/10] DOCS-792: additional clarifications to replica-set reconfiguration text --- source/administration/replica-sets.txt | 35 ++++++++++++++------------ 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/source/administration/replica-sets.txt b/source/administration/replica-sets.txt index 0e6431c6b47..50c792994f4 100644 --- a/source/administration/replica-sets.txt +++ b/source/administration/replica-sets.txt @@ -157,17 +157,19 @@ operations in the :program:`mongo` shell: cfg.members[0].hidden = true rs.reconfig(cfg) -After re-configuring the set, the member with the ``_id`` of ``0`` -has a priority of ``0`` so that it cannot become primary. The -other members in the set will not advertise the hidden member in the -:dbcommand:`isMaster` or :method:`db.isMaster()` output. +After re-configuring the set, the first member of the set in the +:data:`members ` array will have a priority of ``0`` +so that it cannot become primary. The other members in the set will +not advertise the hidden member in the :dbcommand:`isMaster` or +:method:`db.isMaster()` output. .. note:: You must send the :method:`rs.reconfig()` command to a set member - that *can* become :term:`primary`. In the above example, if you issue - the :method:`rs.reconfig()` operation to the member with the ``_id`` - of ``0``, the operation fails. + that *can* become :term:`primary`. In the above example, if you + issue the :method:`rs.reconfig()` operation to a member with a + :data:`priority ` of ``0`` the operation will + fail. .. note:: @@ -225,8 +227,8 @@ following sequence of operations in the :program:`mongo` shell: cfg.members[0].slaveDelay = 3600 rs.reconfig(cfg) -After the replica set reconfigures, the set member with the ``_id`` of -``0`` has a priority of ``0`` and cannot become :term:`primary`. The :data:`slaveDelay ` value +After the replica set reconfigures, the first member of the set in the +:data:`members ` array will have a priority of ``0`` and cannot become :term:`primary`. The :data:`slaveDelay ` value delays both replication and the member's :term:`oplog` by 3600 seconds (1 hour). Setting :data:`slaveDelay ` to a non-zero value also sets :data:`hidden ` to @@ -314,13 +316,14 @@ command sequence in the :program:`mongo` shell. cfg.members[5].votes = 0 rs.reconfig(cfg) -This sequence gives ``0`` votes to set members with the ``_id`` -values of ``3``, ``4``, and ``5``. This setting allows the set to -elect these members as :term:`primary` but does not allow them to -vote in elections. If you have three non-voting members, you can add -three additional voting members to your set. Place voting members so that -your designated primary or primaries can reach a majority of votes in -the event of a network partition. +This sequence gives ``0`` votes to the fourth, fifth, and sixth +members of the set according to the order of the :data:`members +` array in the output of :method:`rs.conf()`. This +setting allows the set to elect these members as :term:`primary` but +does not allow them to vote in elections. If you have three non-voting +members, you can add three additional voting members to your +set. Place voting members so that your designated primary or primaries +can reach a majority of votes in the event of a network partition. .. note:: From ffb2af1e0a324726c385f9313c6cd37530f87460 Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Mon, 26 Nov 2012 15:11:16 -0500 Subject: [PATCH 10/10] DOCS-790 updates and clarification for the ensureIndex reference page --- .../method/db.collection.ensureIndex.txt | 53 +++++++++++++------ 1 file changed, 38 insertions(+), 15 deletions(-) diff --git a/source/reference/method/db.collection.ensureIndex.txt b/source/reference/method/db.collection.ensureIndex.txt index c52345fe8c6..6dd353be83c 100644 --- a/source/reference/method/db.collection.ensureIndex.txt +++ b/source/reference/method/db.collection.ensureIndex.txt @@ -20,6 +20,9 @@ db.collection.ensureIndex() characters. See the :method:`db.collection.getIndexes()` field ":data:`name`" for the names of existing indexes. + .. see:: The :doc:`/indexes` section of this manual for full + documentation of indexes and indexing in MongoDB. + Creates an index on the field specified, if that index does not already exist. If the ``keys`` document specifies more than one field, than :method:`db.collection.ensureIndex()` creates a :term:`compound @@ -47,18 +50,37 @@ db.collection.ensureIndex() The available options, possible values, and the default settings are as follows: - ==================== ================= ========= - Option Value Default - ==================== ================= ========= - background true or false false - unique true or false false - name string none - cache true or false true - dropDups true or false false - sparse true or false false - expireAfterSeconds integer none - v index version. 1 [#]_ - ==================== ================= ========= + .. list-table:: + :header-rows: 1 + + * - **Option** + - **Plugin** + - **Default** + + * - background + - ``true`` or ``false`` + - ``false`` + * - unique + - ``true`` or ``false`` + - ``false`` + * - name + - string + - none + * - cache + - ``true`` or ``false`` + - ``true`` + * - dropDups + - ``true`` or ``false`` + - ``false`` + * - sparse + - ``true`` or ``false`` + - ``false`` + * - expireAfterSeconds + - integer + - none + * - v + - index version + - 1 :option Boolean background: Specify ``true`` to build the index in the background so that building an @@ -82,8 +104,10 @@ db.collection.ensureIndex() :option Boolean dropDups: Specify ``true`` when creating a unique index, on a field that *may* have duplicate to index only the first - occurrence of a key, and ignore - subsequent occurrences of that key. + occurrence of a key, and **remove** all + documents from the collection that + contain subsequent occurrences of that + key. :option Boolean sparse: If ``true``, the index only references documents with the specified field. These @@ -130,7 +154,6 @@ db.collection.ensureIndex() :ref:`indexes-admin-stop-in-progress-build` for more information. - .. [#] 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.