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

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

**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 `index.hidden` collection option set
using the [`collMod`](https://www.mongodb.com/docs/manual/reference/command/collmod.md#mongodb-dbcommand-dbcmd.collMod) command.

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

## Definition

Hides an existing index from the query planner. An [index hidden from the query planner](https://www.mongodb.com/docs/manual/core/index-hidden.md#std-label-index-type-hidden) is not evaluated as part of query plan selection.

By hiding an index from the planner, you can evaluate the potential impact of dropping an index without actually dropping the index. If the impact is negative, you can unhide the index instead of having to recreate a dropped index. And because indexes are fully maintained while hidden, the indexes are immediately available for use once unhidden.

For details, see [Hidden Indexes.](https://www.mongodb.com/docs/manual/core/index-hidden.md#std-label-index-type-hidden)

## 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

**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

```javascript
db.collection.hideIndex(<index>)
```

### Parameters

The [`db.collection.hideIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.hideindex.md#mongodb-method-db.collection.hideIndex) method takes the following parameter:

| Parameter | Type | Description |
| --- | --- | --- |
| `index` | string or document | Specifies the index to hide from the query planner. You can specify the index either by the index name or by the index specification document. To find the index name or index specification document, you can use the [`db.collection.getIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.getindexes.md#mongodb-method-db.collection.getIndexes) method. To hide a [text](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-text.md#std-label-index-type-text) index, specify the index name. |

The [`db.collection.hideIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.hideindex.md#mongodb-method-db.collection.hideIndex) is a [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh) shell wrapper for the [`collMod`](https://www.mongodb.com/docs/manual/reference/command/collmod.md#mongodb-dbcommand-dbcmd.collMod) command.

## Behavior

### Feature Compatibility Version

To hide an index, you must have [featureCompatibilityVersion](https://www.mongodb.com/docs/manual/reference/command/setfeaturecompatibilityversion.md#std-label-view-fcv) set to `7.0` or greater.

### Restrictions

You cannot hide the `_id` index.

### Index Modifications Reset Statistics

Hiding an unhidden index resets its [`$indexStats`.](https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexstats.md#mongodb-pipeline-pipe.-indexStats)

### No-op

Hiding an already hidden index has no effect on the index. However, the operation will still generate an empty oplog entry.

## Access Control

If the deployment enforces authentication/authorization, you must have the [`collMod`](https://www.mongodb.com/docs/manual/reference/privilege-actions.md#mongodb-authaction-collMod) privilege in the collection's database.

The built-in role [`dbAdmin`](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#mongodb-authrole-dbAdmin) provides the required privileges.

## Example

The following example hides an existing index.

First, use [`db.collection.createIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.createindex.md#mongodb-method-db.collection.createIndex) to create an index without hiding:

```javascript
db.restaurants.createIndex( { borough: 1, ratings: 1 } );
```

To hide the index, you can specify either the index key specification document or the index name to the [`db.collection.hideIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.hideindex.md#mongodb-method-db.collection.hideIndex) method. The following specifies the index name:

```javascript
db.restaurants.hideIndex( "borough_1_ratings_1" );
```

To verify, run [`db.collection.getIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.getindexes.md#mongodb-method-db.collection.getIndexes) on the `restaurants` collection:

```javascript
db.restaurants.getIndexes();
```

The operation returns the following information:

```javascript
[
   {
      "v" : 2,
      "key" : {
         "_id" : 1
      },
      "name" : "_id_"
   },
   {
      "v" : 2,
      "key" : {
         "borough" : 1,
         "ratings" : 1
      },
      "name" : "borough_1_ratings_1",
      "hidden" : true
   }
]
```

The `hidden` index option is only returned if the value is `true`.

**See also:**

- [`db.collection.unhideIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.unhideindex.md#mongodb-method-db.collection.unhideIndex)

- [db.collection.createIndex()](https://www.mongodb.com/docs/manual/reference/method/db.collection.createindex.md#std-label-method-createIndex-hidden)
