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

# db.collection.checkMetadataConsistency() (mongosh method)

## Definition

Performs a series of consistency checks on sharding metadata for the collection. The method returns a cursor with either all or a batch of the inconsistency results found.

**Important: mongosh Method**

This page documents a [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) method. This is *not* the documentation for database commands or language-specific drivers, such as Node.js.

For the database command, see the [`checkMetadataConsistency`](https://www.mongodb.com/docs/manual/reference/command/checkmetadataconsistency.md#mongodb-dbcommand-dbcmd.checkMetadataConsistency) command.

For MongoDB API drivers, refer to the language-specific [MongoDB driver documentation.](https://www.mongodb.com/docs/drivers/)

Run this method after major maintenance operations, such as upgrades and downgrades, to check the state of the catalog.

By default, the method does not check indexes for consistency across the shards. Index checks can return false positive inconsistencies if they run concurrent with operations that create, delete, or modify indexes.  To check indexes with this method, set the `checkIndexes` option.

For more information on the inconsistencies this method checks for, see [Inconsistency Types.](https://www.mongodb.com/docs/manual/reference/inconsistency-type.md#std-label-inconsistency-types)

This method returns a cursor with a `documents` array, which contains a document for each inconsistency found in the sharding metadata.

## Compatibility

This method 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

**Important:**

This command is not supported in M0 and Flex clusters. For more information, 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

**Note:**

The `checkMetadataConsistency` helper is executable only when connecting to `mongos`. `mongod` does not support this method.

## Syntax

The [`db.collection.checkMetadataConsistency()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.checkmetadataconsistency.md#mongodb-method-db.collection.checkMetadataConsistency) method has the following syntax:

```javascript
db.collection.checkMetadataConsistency( { <options> } )
```

The `options` document can take the following fields and values:

| Field | Type | Description |
| --- | --- | --- |
| `checkIndexes` | boolean | Sets whether the command also checks indexes in sharding metadata. By default, this operation is disabled, because if it can return false positives inconsistencies when run concurrent with operations that create, delete, or modify indexes.  Only check indexes at times when you know these operations are unlikely to occur. |
| `cursor` | document | Configures the return cursor. |
| `cursor.batchSize` | integer | Maximum number of sharding metadata inconsistency documents to include in each batch. |
| `performStrictChunkChecksIfBelowThreshold` | integer | **New in version 9.0** Optional. Chunk-count threshold that determines how thoroughly the command compares a shard's chunk metadata for the checked collection. The default value is `1152921504606846975` (2 60 - 1) chunks, which means that by default, the command always performs the strict check with full comparison. For more information, see [Chunk Check Threshold.](https://www.mongodb.com/docs/manual/reference/command/checkmetadataconsistency.md#std-label-checkMetadataConsistency-chunk-check-threshold) |

## Example

```javascript
db.authors.checkMetadataConsistency()
```

**Output:**

```json
{
   cursorHasMore: false,
   documents: [
      {
         type: "MisplacedCollection",
         description: "Unsharded collection found on shard different from database primary shard",
         details: {
            namespace: "test.authors",
            shard: "shard02",
            localUUID: new UUID("1ad56770-61e2-48e9-83c6-8ecefe73cfc4")
         }
      }
   ],
}
```
