> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# setIndexCommitQuorum (database command)

The `setIndexCommitQuorum` command sets minimum number of data-bearing members that must be prepared to commit their local index builds before the primary node will commit the index.

## Compatibility

This command is available in deployments hosted in the following environments:

- [MongoDB Atlas](https://www.mongodb.com/docs/atlas): The fully managed service for MongoDB deployments in the cloud

**Note:**

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see [Unsupported Commands.](https://www.mongodb.com/docs/atlas/unsupported-commands/)

- [MongoDB Enterprise](https://www.mongodb.com/docs/manual/administration/install-enterprise.md#std-label-install-mdb-enterprise): The subscription-based, self-managed version of MongoDB

- [MongoDB Community](https://www.mongodb.com/docs/manual/administration/install-community.md#std-label-install-mdb-community-edition): The source-available, free-to-use, and self-managed version of MongoDB

## Syntax

The command has the following syntax:

```javascript
db.runCommand(
   {
     setIndexCommitQuorum: <string>,
     indexNames: [ <document> ],
     commitQuorum: <int> | <string>,
     comment: <any>
   }
)
```

## Command Fields

The command takes the following fields:

| Field | Type | Description |
| --- | --- | --- |
| [setIndexCommitQuorum](https://www.mongodb.com/docs/manual/reference/command/setindexcommitquorum.md#std-label-setIndexCommitQuorum-cmd-coll) | `string` | The name of the collection for which the indexes are being built. |
| [indexNames](https://www.mongodb.com/docs/manual/reference/command/setindexcommitquorum.md#std-label-setIndexCommitQuorum-cmd-indexNames) | `array` | An array of in-progress index builds to modify. Each element of the array must be the *name* of the index. The indexes specified to `indexNames` must be the entire set of in-progress builds associated to a given index builder, i.e. the indexes built by a single [`createIndexes`](https://www.mongodb.com/docs/manual/reference/command/createindexes.md#mongodb-dbcommand-dbcmd.createIndexes) or [`db.collection.createIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.createindexes.md#mongodb-method-db.collection.createIndexes) operation. |
| [commitQuorum](https://www.mongodb.com/docs/manual/reference/command/setindexcommitquorum.md#std-label-setIndexCommitQuorum-cmd-commitQuorum) | `int` or `string` | The minimum number of data-bearing replica set members (i.e. commit quorum), including the primary, that must report a successful [index build](https://www.mongodb.com/docs/manual/core/index-creation.md#std-label-index-operations-replicated-build) before the primary marks the `indexes` as ready. You can resume some [interrupted index builds](https://www.mongodb.com/docs/manual/core/index-creation.md#std-label-index-operations-build-failure) when the commit quorum is set to the default `"votingMembers"`. To update the commitQuorum, member replica set nodes must have [`members[n].buildIndexes`](https://www.mongodb.com/docs/manual/reference/replica-configuration.md#mongodb-rsconf-rsconf.members-n-.buildIndexes) set to `true`. If any voting nodes have `members[n].buildIndexes` set to `false`, you can't use the default `"votingMembers"` commit quorum. Either configure all nodes with `members[n].buildIndexes` set to `true`, or select a different commit quorum. Supports the following values: `"votingMembers"` - all data-bearing voting replica set members (*Default*). A "voting" member is any replica set member where [`members[n].votes`](https://www.mongodb.com/docs/manual/reference/replica-configuration.md#mongodb-rsconf-rsconf.members-n-.votes) is greater than `0`.; `"majority"` - a simple majority of data-bearing replica set members.; `<int>` - a specific number of data-bearing replica set members. Specify an integer greater than `0`.; A replica set [tag name.](https://www.mongodb.com/docs/manual/tutorial/configure-replica-set-tag-sets.md) |
| `comment` | any | Optional. A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations: [mongod log messages](https://www.mongodb.com/docs/manual/reference/log-messages.md#std-label-log-messages-ref), in the `attr.command.cursor.comment` field.; [Database profiler](https://www.mongodb.com/docs/manual/reference/database-profiler.md#std-label-profiler) output, in the [`command.comment`](https://www.mongodb.com/docs/manual/reference/database-profiler.md#mongodb-data-system.profile.command) field.; [`currentOp`](https://www.mongodb.com/docs/manual/reference/command/currentop.md#mongodb-dbcommand-dbcmd.currentOp) output, in the [`command.comment`](https://www.mongodb.com/docs/manual/reference/command/currentop.md#mongodb-data-currentOp.command) field. A comment can be any valid [BSON type](https://www.mongodb.com/docs/manual/reference/bson-types.md#std-label-bson-types) (string, integer, object, array, etc). |

## Behavior

**Note: Requires featureCompatibilityVersion 4.4+**

Each [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) in the replica set or sharded cluster *must* have [featureCompatibilityVersion](https://www.mongodb.com/docs/manual/reference/command/setfeaturecompatibilityversion.md#std-label-set-fcv) set to at least `4.4` to start index builds simultaneously across replica set members.

Index creation is a [multistage process](https://www.mongodb.com/docs/manual/core/index-creation.md#std-label-index-build-process). The index creation process uses the `commit quorum` to minimize replication lag on secondary nodes.

When a secondary node receives a `commitIndexBuild` oplog entry, the node stops further oplog applications until the local index build can be committed. Index builds can take anywhere from moments to days to complete, so the replication lag can be significant if the secondary node builds more slowly than the primary.

To manage the replication lag, the commit quorum delays committing the index build on the primary node until a minimum number of secondaries are also ready to commit the index build.

The commit quorum does not guarantee that indexes on secondaries are ready for use when the command completes. To ensure that a specific number of secondaries are ready for use, set an appropriate [write concern.](https://www.mongodb.com/docs/manual/reference/write-concern.md#std-label-write-concern)

If a secondary node that is not included in the commit quorum receives a `commitIndexBuild` oplog entry, the node may block replication until its index build is complete.

Issuing [`setIndexCommitQuorum`](https://www.mongodb.com/docs/manual/reference/command/setindexcommitquorum.md#mongodb-dbcommand-dbcmd.setIndexCommitQuorum) has no effect on index builds started with [commitQuorum](https://www.mongodb.com/docs/manual/reference/command/createindexes.md#std-label-createIndexes-cmd-commitQuorum) of `0`.

**Important:**

Replica set nodes with [buildIndexes](https://www.mongodb.com/docs/manual/reference/replica-configuration.md#std-label-replica-set-configuration-buildIndexes) set to `false` can't be included in a commit quorum.

### Commit Quorum Contrasted with Write Concern

There are important differences between [commit quorums](https://www.mongodb.com/docs/manual/reference/command/createindexes.md#std-label-createIndexes-cmd-commitQuorum) and [write concerns:](https://www.mongodb.com/docs/manual/reference/write-concern.md#std-label-write-concern)

- Index builds use commit quorums.

- Write operations use write concerns.

Each data-bearing node in a cluster is a voting member.

The commit quorum specifies how many data-bearing voting members, or which voting members, including the primary, must be prepared to commit a [simultaneous index build](https://www.mongodb.com/docs/manual/core/index-creation.md#std-label-index-operations-simultaneous-build) before the primary will execute the commit.

The write concern is the level of acknowledgment that the write has propagated to the specified number of instances.

**Changed in version 8.0**

The commit quorum specifies how many
nodes must be ready to finish the index build before the
primary commits the index build. In contrast, when the
primary has committed the index build, the write concern
specifies how many nodes must replicate the index build oplog
entry before the command returns success.

In previous releases, when the primary committed the index build, the write concern specified how many nodes must finish the index build before the command returned success.

## Examples

Index builds on a replica set or sharded cluster build simultaneously across all data-bearing replica set members. For sharded clusters, the index build occurs only on shards containing data for the collection being indexed. The primary requires a minimum number of data-bearing [`voting`](https://www.mongodb.com/docs/manual/reference/replica-configuration.md#mongodb-rsconf-rsconf.members-n-.votes) members (i.e commit quorum), including itself, that must complete the build before marking the index as ready for use. See [Index Builds in Replicated Environments](https://www.mongodb.com/docs/manual/core/index-creation.md#std-label-index-operations-replicated-build) for more information.

The following operation starts an index build of two indexes:

```javascript
db.getSiblingDB("examples").invoices.createIndexes(
  [
    { "invoices" : 1 },
    { "fulfillmentStatus" : 1 }
  ]
)
```

By default, index builds use `"votingMembers"` commit quorum, or all data-bearing voting replica set members. The following operation modifies the index build commit quorum to `"majority"`, or a simple majority of data-bearing voting members:.

```javascript
db.getSiblingDB("examples").runCommand(
  {
    "setIndexCommitQuorum" : "invoices",
    "indexNames" : ["invoices_1", "fullfillmentStatus_1"],
    "commitQuorum" : "majority"
  }
)
```

- The indexes specified to `indexNames` must be the entire set of in-progress builds associated to a given index builder, i.e. the [`createIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.createindexes.md#mongodb-method-db.collection.createIndexes) operation.

- The `indexNames` field specifies the *names* of the indexes. Since the indexes were created without an explicit name, MongoDB generated an index name by concatenating the names of the indexed fields and the sort order.
