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

<!--
Tab options on this page. Append to the .md URL to filter:
  ?tabs=<id,...>   select specific tabs (e.g. ?tabs=nodejs,shell)
  ?allTabs=true    include every tab
  (no param)       default: one tab per tabset

Available tabs:
  other tabs: fts-vs, data-explorer, vib, jsonib, create-one, create-multiple
-->

# Manage MongoDB Search Indexes

A MongoDB Search index is a data structure that maps documents from your Atlas cluster to the terms that are extracted from those documents. MongoDB Search indexes enable efficient full-text searches of your database with MongoDB Search queries.

This page describes how to create, view, update, or delete MongoDB Search indexes using the Atlas UI or one of our supported clients.

## Supported Clients

You can create and manage MongoDB Search indexes from the Atlas UI or one of the following supported clients:

- Atlas CLI, with Atlas cluster running MongoDB 7.0+

- [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh), with Atlas cluster running MongoDB 7.0+.

- [Compass](https://www.mongodb.com/try/download/compass), with Atlas cluster running MongoDB 7.0+.

- Supported [MongoDB Drivers:](https://www.mongodb.com/docs/drivers/)

  | MongoDB Driver | Driver Version |
  | --- | --- |
  | [C](https://www.mongodb.com/docs/drivers/c/) | 1.25.0 or higher |
  | [C++](https://www.mongodb.com/docs/drivers/cxx/) | 3.9.0 or higher |
  | [C#](https://www.mongodb.com/docs/drivers/csharp/current/) | 2.21.0 or higher |
  | [Go](https://www.mongodb.com/docs/drivers/go/current/) | 1.13.0 or higher |
  | [Java](https://www.mongodb.com/docs/drivers/java-drivers/) | 4.11.0 or higher |
  | [Mongoid](https://www.mongodb.com/docs/mongoid/?tck=docs) | 9.0 or higher |
  | [Motor](https://www.mongodb.com/docs/drivers/motor/) | 3.3.0 or higher |
  | [Kotlin](https://www.mongodb.com/docs/drivers/kotlin/) | 5.2.0 or higher |
  | [Node](https://www.mongodb.com/docs/drivers/node/current/) | 5.6.0 or higher |
  | [PHP](https://www.mongodb.com/docs/drivers/php-drivers/) | 1.17.0 or higher |
  | [Python](https://www.mongodb.com/docs/drivers/python-drivers/) | 4.5 or higher |
  | [Ruby](https://www.mongodb.com/docs/drivers/ruby-drivers/) | 2.19.2 or higher |
  | [Rust](https://www.mongodb.com/docs/drivers/rust/current/) | 2.8.0 or higher |
  | [Scala](https://www.mongodb.com/docs/drivers/scala/) | 5.2.0 or higher |

## Required Access

You can assign [Project User Roles](https://www.mongodb.com/docs/atlas/reference/user-roles.md#std-label-project-roles) or [Database Built-in User Roles](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#std-label-mongodb-users-roles-and-privileges) to provide access to the user privileges necessary to perform the MongoDB Search index actions described in this guide:

- The following table shows the modes of access that the following [Project User Roles](https://www.mongodb.com/docs/atlas/reference/user-roles.md#std-label-project-roles) support for the specified MongoDB Search actions:

  | Project User Role | MongoDB Search Action | Atlas UI | Atlas CLI | Atlas API |
  | --- | --- | --- | --- | --- |
  | [`Project Data Access Read Only`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Data-Access-Read-Only) or higher | To view MongoDB Search indexes and analyzers. | ✓ |  | ✓ |
  | [`Project Data Access Admin`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Data-Access-Admin) or higher | To create, view, update, and delete MongoDB Search indexes and analyzers. | ✓ | ✓ | ✓ |
  | [`Project Search Index Editor`](https://www.mongodb.com/docs/atlas/reference/user-roles.md#mongodb-authrole-Project-Search-Index-Editor) | To create, view, update, and delete MongoDB Search indexes. | ✓ | ✓ | ✓ |

  Each role grants permission to call either a subset or the full set of [MongoDB Search API endpoints](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/group/endpoint-atlas-search) in the Atlas Administration API. See the MongoDB Search Action column for descriptions of the API endpoints that each role grants access to.

- The following table shows the [Database Built-in User Roles](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#std-label-mongodb-users-roles-and-privileges) that support the specified [MongoDB Search Index Privilege Actions.](https://www.mongodb.com/docs/manual/reference/privilege-actions/#atlas-search-index-actions)

  | Database Built-in User Roles | MongoDB Search Action Description | MongoDB Search Index Privilege Action |
  | --- | --- | --- |
  | [`read`](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#mongodb-atlasrole-read) or [`readAnyDatabase`](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#mongodb-atlasrole-readAnyDatabase) | To view MongoDB Search indexes and analyzers. | [listSearchIndexes](https://www.mongodb.com/docs/manual/reference/privilege-actions/#mongodb-authaction-listSearchIndexes) |
  | [`readWrite`](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#mongodb-atlasrole-readWrite) or [`readWriteAnyDatabase`](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#mongodb-atlasrole-readWriteAnyDatabase) | To create, view, update, and delete MongoDB Search indexes and analyzers. | [createSearchIndexes](https://www.mongodb.com/docs/manual/reference/privilege-actions/#mongodb-authaction-createSearchIndexes), [listSearchIndexes](https://www.mongodb.com/docs/manual/reference/privilege-actions/#mongodb-authaction-listSearchIndexes) [updateSearchIndex](https://www.mongodb.com/docs/manual/reference/privilege-actions/#mongodb-authaction-updateSearchIndex), and [dropSearchIndex](https://www.mongodb.com/docs/manual/reference/privilege-actions/#mongodb-authaction-dropSearchIndex) |

  To learn more, see [Built-In Roles](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#std-label-atlas-user-privileges) or [Built-In Roles.](https://www.mongodb.com/docs/manual/reference/built-in-roles.md#std-label-atlas-specific-privileges)

## Create a MongoDB Search Index

To create a MongoDB Search index using the Atlas UI:

1. In Atlas, go to the Search & Vector Search page for your cluster.

   You can go the MongoDB Search page from the Search & Vector Search option, or the Data Explorer.

   ### Search & Vector Search

   If it's not already displayed, select the organization that contains your project from the  Organizations menu in the navigation bar.

   If it's not already displayed, select your project from the Projects menu in the navigation bar.

   In the sidebar, click Search & Vector Search under the Database heading.

   - If you have no clusters, click Create cluster to create one. To learn more, see [Create an Atlas Infinite or Atlas Core Cluster.](https://www.mongodb.com/docs/atlas/tutorial/create-new-cluster.md#std-label-create-new-cluster)

   - If your project has multiple clusters, select the cluster you want to use from the Select cluster dropdown, then click Go to Search.

   The [Search & Vector Search](https://cloud.mongodb.com/go?l=https%3A%2F%2Fcloud.mongodb.com%2Fv2%2F%3Cproject%3E%23%2Fclusters%2FatlasSearch%2F%3Ccluster%3E) page displays.

2. Click Create Search Index.

3. Start your index configuration.

   Make the following selections on the page and then click Next.

   | Search Type | Select the MongoDB Search index type. |
   | --- | --- |
   | Index Name and Data Source | Specify the following information: Index Name: `default`; Database and Collection:name of the database; name of the collection |
   | Configuration Method | For a guided experience, select Visual Editor.To edit the raw index definition, select JSON Editor. |

   IMPORTANT: The default index name varies by index type: your MongoDB Search index is named `default`, your Vector Search index is named `vector_index`, and your Automated Embedding index is named `autoembed_index`. If you are creating multiple indexes, we recommend that you maintain a consistent, descriptive naming convention across your indexes.

4. Review the default MongoDB Search index configuration settings in the Index Configurations section.

   The default index definition is a [dynamic mapping](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings) of the fields in the documents and will work with any collection.

   To customize your index definition, review the following index configurations:

   ### Visual Editor

   | Visual Editor Field | Description | Necessity |
   | --- | --- | --- |
   | Index Analyzer | Specify the [analyzer](https://www.mongodb.com/docs/search/indexes/analyzers/overview.md#std-label-analyzers-ref) to use for indexing the collection data. By default, MongoDB Search uses the [standard](https://www.mongodb.com/docs/search/indexes/analyzers/standard.md#std-label-ref-standard-analyzer) analyzer (`lucene.standard`). Corresponds to the  `analyzer` JSON (Javascript Object Notation) setting. | Optional |
   | Search Analyzer | Specifies the [analyzer](https://www.mongodb.com/docs/search/indexes/analyzers/overview.md#std-label-analyzers-ref) to apply to query text before searching the text. If you omit this field, the index inherits an analyzer by default in the following order: The `analyzer` option for this field if specified.The `searchAnalyzer` option for the [index](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions) if specified.The `analyzer` option for the [index](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions) if specified.The `lucene.standard` analyzer. Corresponds to the  `searchAnalyzer` JSON (Javascript Object Notation) setting. | Optional |
   | Dynamic Mapping | Specify dynamic or static mapping of fields. By default, dynamic mapping is enabled. To disable dynamic mapping, set `dynamic` to `Off`. If you disable dynamic mapping, you must specify the fields to index. To learn more about dynamic and static mappings, see [Define Field Mappings for a MongoDB Search Index.](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-fts-field-mappings) Corresponds to the  `mappings.dynamic` JSON (Javascript Object Notation) setting. | Required |

   If you are satisfied with the default configuration, skip ahead. If you wish to refine your MongoDB Search index, proceed to the next step.

5. Refine your MongoDB Search index to configure additional settings.

   ### Visual Editor

   Click Refine Your Index to make changes to any of the following settings.

   | Field Name | Description | Necessity |
   | --- | --- | --- |
   | Field Mappings | Required if Dynamic Mapping in the Index Configurations section is disabled. Specify the fields to index: Click Add Field Mapping to open the Add Field Mapping window.Specify the following information about the field:Field name - Name of the field to index.; Data Type - Field data type. To learn more about the supported data types and their options, see [MongoDB Search Field Types.](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-bson-data-chart)*(Optional)* Specify additional properties.A table of additional configuration options appears in the Add Field Mapping window. These properties depend on the data type that you selected in the last step.To learn more about the supported data types and their options, see [MongoDB Search Field Types.](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-bson-data-chart)*(Optional)* Add multi field.Click Add Multi Field to configure an alternative field analyzer with which to index the field. To learn more, see [Multi Analyzer.](https://www.mongodb.com/docs/search/indexes/analyzers/multi.md#std-label-ref-multi-analyzers)Click Add to add the field.You can click the ellipses (...) icon for the field in the Actions column to do the following:Click Edit to modify the configuration.; Click Add Data Type to configure additional data types for the field.; Click Delete to remove the field from the index. To learn more about defining field mappings, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions) Corresponds to the  `mappings.fields` JSON (Javascript Object Notation) setting. | Conditional |
   | Stored Source Fields | Specify the fields to store on MongoDB Search for query-time lookups. You can store fields of all supported [MongoDB Search Field Types](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-bson-data-chart) on MongoDB Search. To learn more about storing fields, see [Define Stored Source Fields in Your MongoDB Search Index.](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition) Corresponds to the `storedSource` JSON (Javascript Object Notation) setting. | Optional |
   | Synonyms Mappings | Specify synonym mappings to use in your index. You can use a synonym mapping to query only fields analyzed with the same analyzer. To learn more about synonym mappings, see [Define Synonym Mappings in Your MongoDB Search Index.](https://www.mongodb.com/docs/search/indexes/synonyms.md#std-label-synonyms-ref) Corresponds to the `synonyms` JSON (Javascript Object Notation) setting. | Optional. |
   | Index Partitions | The number of partitions to use if field objects exceed 2.1 billion. Corresponds to the `numPartitions` JSON (Javascript Object Notation) setting. | Optional. |

   Click Save Changes.

6. *Optional.* If you use the Visual Editor, you can save or delete your index definition draft.

   IMPORTANT: You can't save the [default index definition](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-manage-indexes) as a draft. If you use the Visual Editor and your index definition contains [static mappings](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings), you can save an index definition as a draft.

   Click Cancel.

   Click Save Draft or Delete Draft.

   WARNING: You can't create a new index when you have a pending index draft.

   To learn more, see [Resume or Delete a MongoDB Search Index Draft.](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-ref-resume-index)

7. Click Create Search Index.

   Atlas displays a Toast (brief, non-interactive notification) to let you know your index is building.

8. Check the status.

   The newly created index appears on the Atlas Search tab. While the index is building, the Status field reads Building. When the index is finished building, the Status field reads Ready.

   IMPORTANT: Larger collections take longer to index. You will receive an email notification when your index is finished building.

## View MongoDB Search Indexes

To view the Atlas UI MongoDB Search page:

1. In Atlas, go to the Search & Vector Search page for your cluster.

   You can go the MongoDB Search page from the Search & Vector Search option, or the Data Explorer.

   ###### Search & Vector Search

   If it's not already displayed, select the organization that contains your project from the  Organizations menu in the navigation bar.

   If it's not already displayed, select your project from the Projects menu in the navigation bar.

   In the sidebar, click Search & Vector Search under the Database heading.

   If your project has multiple clusters, select the cluster you want to use from the Select cluster dropdown, then click Go to Atlas Search.

   The [Search & Vector Search](https://cloud.mongodb.com/go?l=https%3A%2F%2Fcloud.mongodb.com%2Fv2%2F%3Cproject%3E%23%2Fclusters%2FatlasSearch%2F%3Ccluster%3E) page displays.

   ###### Data Explorer

   If it's not already displayed, select the organization that contains your project from the  Organizations menu in the navigation bar.

   If it's not already displayed, select your project from the Projects menu in the navigation bar.

   In the sidebar, click Data Explorer under the Database heading.

   Expand the database and select the collection.

   Click the Indexes tab for the collection.

   Click the Search and Vector Search link in the banner.

   The [Search & Vector Search](https://cloud.mongodb.com/go?l=https%3A%2F%2Fcloud.mongodb.com%2Fv2%2F%3Cproject%3E%23%2Fclusters%2FatlasSearch%2F%3Ccluster%3E%3Fdatabase%3Dsample_mflix%26collectionName%3Dusers) page displays.

The MongoDB Search page in the Atlas UI displays details about all of the MongoDB Search indexes on a cluster.

This page contains a table with the following details for each of your MongoDB Search indexes in each column:

| Column | Description |
| --- | --- |
| Database | Name of the database that contains the collection. |
| Collection | Name of the indexed collection. |
| Index Name | Name of the index. |
| Status | Status of the index on the primary node of the cluster. To learn more, see [MongoDB Search Index Statuses.](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status) |
| Queryable | Icon that identifies whether collection is queryable using the index. Value can be one of the following icons: - for indexes that you can use to query the collection.; X - for indexes that you can't use to query the collection. |
| Type | Type of index. Value can be one of the following types of index: `search` - for running [`$search`](https://www.mongodb.com/docs/search/query/aggregation-stages/search.md#mongodb-pipeline-pipe.-search) and [`$searchMeta`](https://www.mongodb.com/docs/search/query/aggregation-stages/searchmeta.md#mongodb-pipeline-pipe.-searchMeta) queries.; `vectorSearch` - for running [`$vectorSearch`](https://www.mongodb.com/docs/vector-search/query/aggregation-stages/vector-search-stage.md#mongodb-pipeline-pipe.-vectorSearch) queries. |
| Index Fields | Indexed fields. Value is `dynamic` if you enabled [dynamic mappings](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings). For [static mappings](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings), the column shows all of the indexed fields. |
| Documents | Approximate number and percentage of indexed documents out of the total number of documents in the collection during and after the index build on the primary or search node on the cluster. |
| Size | Size of the index. |
| Required Memory | Approximate amount of memory required to run queries. Applies only to MongoDB Vector Search indexes. |
| Actions | Actions you can take on the index: Click Query to go to the Search Tester for querying the collection.; Click  and select one of the following actions to take on the index:[Edit](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-ref-edit-index) the index using the Visual Editor or JSON Editor.; [Delete](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-ref-delete-index) the index. |

By default, Atlas sorts the indexes first by database name, then collection name. To sort by multiple columns, press Shift and click the column names according to the sort priority you want.

From this table, you can open the following pages for more details about each index:

### Index Overview

To open the Index Overview page from the table on the MongoDB Search page, click the Index Name of the index that you want to view.

For each index, the Index Overview page shows the [namespace](https://www.mongodb.com/docs/manual/reference/limits/#std-label-faq-dev-namespace) for the index and the following configurations specified in the index definition:

| Row | Description |
| --- | --- |
| Index Analyzer | Chosen text analyzer that specifies how text is processed and tokenized when building the search index. |
| Search Analyzer | Chosen text analyzer that specifies how text in your search queries is processed and tokenized. |
| Dynamic Mapping | Boolean indicating whether or not you enabled [dynamic or static mappings](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings) for your field mappings |
| Field Mappings | Any specified [field mappings](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-fts-field-mappings), including field name, data type, and whether dynamic mapping is enabled for the individual field |
| Stored Source Fields | Any defined [stored source fields](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition) |
| Synonym Mappings | Any defined [synonym mappings](https://www.mongodb.com/docs/search/indexes/synonyms.md#std-label-synonyms-ref) for word equivalents |

To learn how to view index status details from the MongoDB Search page, see [View MongoDB Search Index Statuses.](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-index-statuses)

## View MongoDB Search Index Statuses

The MongoDB Search page in the Atlas UI displays a table of the MongoDB Search indexes for a cluster. The Status column displays the status of the MongoDB Search index on the primary node in the cluster.

Possible index statuses include:

| Status | Description |
| --- | --- |
| Pending | Atlas has not yet started building the index. |
| Building | Atlas is building the index or re-building the index after an edit. When the index is in this state: For a new index, MongoDB Search doesn't serve queries until the index build is complete.; For an existing index, you can continue to use the old index for existing and new queries until the index rebuild is complete. |
| Ready | Index is ready to use. |
| Stale | Index is stale because of any of the following reasons: Replication stopped due to high disk utilization.For dedicated `mongot` nodes, the pause replication threshold is 90% and the resume replication threshold is 85% disk utilization. For colocated `mongot` nodes, the pause replication threshold is 96% and the resume replication threshold is 94% disk utilization.; If replication stops for a long period, the MongoDB Search `mongot` process falls off the oplog.This state commonly occurs when the current replication point is no longer available on the [`mongod`](https://www.mongodb.com/docs/manual/reference/program/mongod.md#mongodb-binary-bin.mongod) oplog. Atlas rebuilds index if the `mongot` process falls off the oplog.; Index reached the two billion document limit.; Replication failed due to an error. You can still query the existing index. However, the results for queries against a stale index might contain stale data. You can upscale your search nodes for more disk space and delete existing indexes to release disk space. Alternatively, use the error in the View status details modal window to troubleshoot the issue. To learn more, see [Fix MongoDB Search Issues.](https://www.mongodb.com/docs/atlas/reference/alert-resolutions/atlas-search-alerts.md#std-label-atlas-search-alerts) |
| Failed | Atlas could not build the index. Use the error in the View status details modal window to troubleshoot the issue. To learn more, see [Fix MongoDB Search Issues.](https://www.mongodb.com/docs/atlas/reference/alert-resolutions/atlas-search-alerts.md#std-label-atlas-search-alerts) |
| Deleting | MongoDB is deleting the index from the cluster nodes. |
| Does not Exist | Index is invalid because the collection for the index no longer exists. You can't run queries on this index because there is no corresponding collection for this index. Atlas will eventually delete the index. |

To view index statuses for more nodes in your cluster, you can open the Status Details page by clicking View status
details in the Status column.

The Status Details page contains the following sections:

### Index Serving Queries

This section displays the index that is being used to serve queries.

If you have only one version of the index with this name for the collection, the section contains a link to the Index
Overview where you can see the index definition for the index being used.

If you had other indexes with the same name on the collection, the section shows the latest index definition and also shows prior valid versions of the index that you can copy in different tabs.

When you update an index, different nodes apply the updates at different speeds. Therefore, some nodes might use the latest version and some might use the prior version. Atlas displays both versions of the index until the changes are applied to all the nodes.

If you attempt to update the index with an invalid index definition, the index build will fail and Atlas displays only the previous valid index definition.

### Status Details by Node

This section displays the status of the index on each node of the cluster. You can see the following details about the index on each node:

| Shard | Shard name. |
| --- | --- |
| Node | Node information. |
| Status | Status of the index on the node in the shard. |
| Queryable | Icon that indicates whether the index can serve queries. |
| Message | Reason for the index status. For indexes in `Stale` or `Failed` state, displays the reason why the index is stale or why the index build failed. |
| Node Type | Type of node. Value can be one of the following types: Primary; Secondary; Search Node |
| Region | Node region. |
| Size | Size of the index on the node. |
| Documents | Number and percentage of indexed documents. |
| Actions | Actions you can take on the index in the node. You can click the  and select one of the following options: [View metrics.](https://www.mongodb.com/docs/atlas/review-atlas-search-metrics.md#std-label-review-atlas-search-metrics); Copy the host name of the node. |

### Migration to Search Nodes

This section displays the status of the in-progress migration of your MongoDB Search and MongoDB Vector Search indexes to search nodes, if applicable. This section displays only if you are currently migrating to search nodes.

Click the View Migration Progress link in the information banner under the Index Status by Search Node section for details on the progress of the migration of the indexes to Search Nodes (on a per node basis).

The Atlas UI displays the following columns for each index on the cluster.

| Column | Description |
| --- | --- |
| Database | Name of the database that contains the collection. |
| Collection | Name of the indexed collection. |
| Index Name | Name of the index. |
| Index Fields | Indexed fields. Value is `dynamic` if you enabled [dynamic mappings](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings). For [static mappings](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings), the column shows all of the indexed fields. |
| Type | Type of index. Value can be one of the following types of index: `search` - for running [`$search`](https://www.mongodb.com/docs/search/query/aggregation-stages/search.md#mongodb-pipeline-pipe.-search) and [`$searchMeta`](https://www.mongodb.com/docs/search/query/aggregation-stages/searchmeta.md#mongodb-pipeline-pipe.-searchMeta) queries.; `vectorSearch` - for running [`$vectorSearch`](https://www.mongodb.com/docs/vector-search/query/aggregation-stages/vector-search-stage.md#mongodb-pipeline-pipe.-vectorSearch) queries. |
| Status | Status of the migration. To learn more, see [Migration to Search Nodes.](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-search-node-migration-status) |
| Size | Size of the index. |
| Documents | Number and percentage of indexed documents out of the total number of documents in the collection during and after the migration on the search nodes on the cluster. |

The status column displays one of the following migration statuses of the index on the Search Nodes:

| Status | Description |
| --- | --- |
| Building | The index is currently building on the Search Node. Your queries can continue to use existing indexes while the new index is building. |
| On Deck | The index is successfully built on the Search Nodes, but the migration is not yet complete. Note that migration is complete only when Atlas successfully builds all the indexes on the Search Nodes. |
| Ready | The index on the Search Node is ready for use in your queries. This displays only when Atlas successfully completes the migration to the Search Nodes. |
| Failed | The index build failed and the migration to separate Search Nodes is stalled. Your queries can continue to use the existing indexes. Atlas will try to rebuild the index, but will timeout after 7 days. To migrate successfully, review error message for the index in the Message column of the Status Details by Node section in the Status Details page and address issues that are causing the index build to fail on the Search Nodes. |

Your queries can continue to use existing indexes while the new indexes are building on the Search Nodes. The migration to the Search Nodes completes only when Atlas successfully builds all the indexes on the Search Nodes. Then, your queries are automatically routed to the use the indexes on the Search Nodes.

**Important:**

You can [resume a change stream](https://www.mongodb.com/docs/manual/changeStreams/#resume-a-change-stream) only while the oplog collection still holds the operation that its [resume token](https://www.mongodb.com/docs/manual/changeStreams/#resume-tokens-from-change-events) identifies. To ensure that your applications can resume their change streams, configure a [Minimum Oplog Window](https://www.mongodb.com/docs/atlas/cluster-additional-settings/#set-oplog-min-window) longer than the longest interruption you expect.

## Resume or Delete a MongoDB Search Index Draft

To resume or delete a MongoDB Search index definition that you saved as a draft in the Atlas UI:

WARNING: You can't create a new index when you have a pending index draft.

1. In Atlas, go to the Search & Vector Search page for your cluster.

   You can go the MongoDB Search page from the Search & Vector Search option, or the Data Explorer.

   ###### Search & Vector Search

   If it's not already displayed, select the organization that contains your project from the  Organizations menu in the navigation bar.

   If it's not already displayed, select your project from the Projects menu in the navigation bar.

   In the sidebar, click Search & Vector Search under the Database heading.

   If your project has multiple clusters, select the cluster you want to use from the Select cluster dropdown, then click Go to Atlas Search.

   The [Search & Vector Search](https://cloud.mongodb.com/go?l=https%3A%2F%2Fcloud.mongodb.com%2Fv2%2F%3Cproject%3E%23%2Fclusters%2FatlasSearch%2F%3Ccluster%3E) page displays.

   ###### Data Explorer

   If it's not already displayed, select the organization that contains your project from the  Organizations menu in the navigation bar.

   If it's not already displayed, select your project from the Projects menu in the navigation bar.

   In the sidebar, click Data Explorer under the Database heading.

   Expand the database and select the collection.

   Click the Indexes tab for the collection.

   Click the Search and Vector Search link in the banner.

   The [Search & Vector Search](https://cloud.mongodb.com/go?l=https%3A%2F%2Fcloud.mongodb.com%2Fv2%2F%3Cproject%3E%23%2Fclusters%2FatlasSearch%2F%3Ccluster%3E%3Fdatabase%3Dsample_mflix%26collectionName%3Dusers) page displays.

2. Click Resume Index Creation.

3. Save or delete your index definition draft.

   Click Cancel.

   Click Save Draft or Delete Draft.

4. Customize your MongoDB Search index configuration settings.

   Click Refine Your Index to make changes to your index configuration.

   Click Save Changes.

5. Click Create Search Index.

   Atlas displays a Toast (brief, non-interactive notification) to let you know your index is building.

6. Check the status.

   The newly created index appears on the Atlas Search tab. While the index is building, the Status field reads Building. When the index is finished building, the Status field reads Ready.

   IMPORTANT: Larger collections take longer to index. You will receive an email notification when your index is finished building.

## Update and Rebuild an Existing MongoDB Search Index

Some MongoDB Search features require that you update the index. To update your index, you can take one of the following actions:

- Edit the index definition using the steps in [Manage MongoDB Search Indexes.](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-ref-edit-index)

- Do the following steps to opt-in for an index update from the Atlas UI:

**Important:**

If Atlas detects insufficient disk space to rebuild the index in place, it automatically provisions new nodes in the background, rebuilds the index, and swaps to the new index seamlessly.

1. In Atlas, go to the Clusters page for your project.

   If it's not already displayed, select the organization that contains your desired project from the  Organizations menu in the navigation bar.

   If it's not already displayed, select your desired project from the Projects menu in the navigation bar.

   In the sidebar, click Clusters under the Database heading.

   The [Clusters](https://cloud.mongodb.com/go?l=https%3A%2F%2Fcloud.mongodb.com%2Fv2%2F%3Cproject%3E%23%2Fclusters) page displays.

2. In Atlas, go to the Search & Vector Search page for your cluster.

   You can go the MongoDB Search page from the Search & Vector Search option, or the Data Explorer.

   ###### Search & Vector Search

   If it's not already displayed, select the organization that contains your project from the  Organizations menu in the navigation bar.

   If it's not already displayed, select your project from the Projects menu in the navigation bar.

   In the sidebar, click Search & Vector Search under the Database heading.

   If your project has multiple clusters, select the cluster you want to use from the Select cluster dropdown, then click Go to Atlas Search.

   The [Search & Vector Search](https://cloud.mongodb.com/go?l=https%3A%2F%2Fcloud.mongodb.com%2Fv2%2F%3Cproject%3E%23%2Fclusters%2FatlasSearch%2F%3Ccluster%3E) page displays.

   ###### Data Explorer

   If it's not already displayed, select the organization that contains your project from the  Organizations menu in the navigation bar.

   If it's not already displayed, select your project from the Projects menu in the navigation bar.

   In the sidebar, click Data Explorer under the Database heading.

   Expand the database and select the collection.

   Click the Indexes tab for the collection.

   Click the Search and Vector Search link in the banner.

   The [Search & Vector Search](https://cloud.mongodb.com/go?l=https%3A%2F%2Fcloud.mongodb.com%2Fv2%2F%3Cproject%3E%23%2Fclusters%2FatlasSearch%2F%3Ccluster%3E%3Fdatabase%3Dsample_mflix%26collectionName%3Dusers) page displays.

3. Click the name of the index that you want to update.

   WARNING: If an index requires an update to enable a new feature, the Atlas UI shows a warning icon next to the index name.

4. Update your index to use the new feature.

   In the Index Overview page, click Update in the banner.

   Click Update Index in the confirmation window.

   While your index is updating, you can continue to query your collection using your previous index.

## Edit a MongoDB Search Index

You can edit a MongoDB Search index to change the [index definition](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions) of an existing MongoDB Search index. You cannot rename an index; if you need to change an index's name, you must create a new index and delete the old one.

To edit a MongoDB Search index using the Atlas UI:

1. In Atlas, go to the Search & Vector Search page for your cluster.

   You can go the MongoDB Search page from the Search & Vector Search option, or the Data Explorer.

   ###### Search & Vector Search

   If it's not already displayed, select the organization that contains your project from the  Organizations menu in the navigation bar.

   If it's not already displayed, select your project from the Projects menu in the navigation bar.

   In the sidebar, click Search & Vector Search under the Database heading.

   If your project has multiple clusters, select the cluster you want to use from the Select cluster dropdown, then click Go to Atlas Search.

   The [Search & Vector Search](https://cloud.mongodb.com/go?l=https%3A%2F%2Fcloud.mongodb.com%2Fv2%2F%3Cproject%3E%23%2Fclusters%2FatlasSearch%2F%3Ccluster%3E) page displays.

   ###### Data Explorer

   If it's not already displayed, select the organization that contains your project from the  Organizations menu in the navigation bar.

   If it's not already displayed, select your project from the Projects menu in the navigation bar.

   In the sidebar, click Data Explorer under the Database heading.

   Expand the database and select the collection.

   Click the Indexes tab for the collection.

   Click the Search and Vector Search link in the banner.

   The [Search & Vector Search](https://cloud.mongodb.com/go?l=https%3A%2F%2Fcloud.mongodb.com%2Fv2%2F%3Cproject%3E%23%2Fclusters%2FatlasSearch%2F%3Ccluster%3E%3Fdatabase%3Dsample_mflix%26collectionName%3Dusers) page displays.

2. Click  and choose one of the following from the dropdown.

   - Edit With Visual Editor for a guided experience.

   - Edit With JSON Editor to edit the raw index definition.

3. Review current configuration settings and edit them as needed.

   ### Visual Editor

   Review the following index configuration settings:

   | Visual Editor Field | Description | Necessity |
   | --- | --- | --- |
   | Index Analyzer | Specify the [analyzer](https://www.mongodb.com/docs/search/indexes/analyzers/overview.md#std-label-analyzers-ref) to use for indexing the collection data. By default, MongoDB Search uses the [standard](https://www.mongodb.com/docs/search/indexes/analyzers/standard.md#std-label-ref-standard-analyzer) analyzer (`lucene.standard`). Corresponds to the  `analyzer` JSON (Javascript Object Notation) setting. | Optional |
   | Search Analyzer | Specifies the [analyzer](https://www.mongodb.com/docs/search/indexes/analyzers/overview.md#std-label-analyzers-ref) to apply to query text before searching the text. If you omit this field, the index inherits an analyzer by default in the following order: The `analyzer` option for this field if specified.The `searchAnalyzer` option for the [index](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions) if specified.The `analyzer` option for the [index](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions) if specified.The `lucene.standard` analyzer. Corresponds to the  `searchAnalyzer` JSON (Javascript Object Notation) setting. | Optional |
   | Dynamic Mapping | Specify dynamic or static mapping of fields. By default, dynamic mapping is enabled. To disable dynamic mapping, set `dynamic` to `Off`. If you disable dynamic mapping, you must specify the fields to index. To learn more about dynamic and static mappings, see [Define Field Mappings for a MongoDB Search Index.](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-fts-field-mappings) Corresponds to the  `mappings.dynamic` JSON (Javascript Object Notation) setting. | Required |

   Review the following advanced configuration settings:

   | Field Name | Description | Necessity |
   | --- | --- | --- |
   | Field Mappings | Required if Dynamic Mapping in the Index Configurations section is disabled. Specify the fields to index: Click Add Field Mapping to open the Add Field Mapping window.Specify the following information about the field:Field name - Name of the field to index.; Data Type - Field data type. To learn more about the supported data types and their options, see [MongoDB Search Field Types.](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-bson-data-chart)*(Optional)* Specify additional properties.A table of additional configuration options appears in the Add Field Mapping window. These properties depend on the data type that you selected in the last step.To learn more about the supported data types and their options, see [MongoDB Search Field Types.](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-bson-data-chart)*(Optional)* Add multi field.Click Add Multi Field to configure an alternative field analyzer with which to index the field. To learn more, see [Multi Analyzer.](https://www.mongodb.com/docs/search/indexes/analyzers/multi.md#std-label-ref-multi-analyzers)Click Add to add the field.You can click the ellipses (...) icon for the field in the Actions column to do the following:Click Edit to modify the configuration.; Click Add Data Type to configure additional data types for the field.; Click Delete to remove the field from the index. To learn more about defining field mappings, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions) Corresponds to the  `mappings.fields` JSON (Javascript Object Notation) setting. | Conditional |
   | Stored Source Fields | Specify the fields to store on MongoDB Search for query-time lookups. You can store fields of all supported [MongoDB Search Field Types](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-bson-data-chart) on MongoDB Search. To learn more about storing fields, see [Define Stored Source Fields in Your MongoDB Search Index.](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition) Corresponds to the `storedSource` JSON (Javascript Object Notation) setting. | Optional |
   | Synonyms Mappings | Specify synonym mappings to use in your index. You can use a synonym mapping to query only fields analyzed with the same analyzer. To learn more about synonym mappings, see [Define Synonym Mappings in Your MongoDB Search Index.](https://www.mongodb.com/docs/search/indexes/synonyms.md#std-label-synonyms-ref) Corresponds to the `synonyms` JSON (Javascript Object Notation) setting. | Optional. |
   | Index Partitions | The number of partitions to use if field objects exceed 2.1 billion. Corresponds to the `numPartitions` JSON (Javascript Object Notation) setting. | Optional. |

4. Click Save to apply the changes.

   The index's status changes from Active to Building. In this state, you can continue to use the old index because MongoDB Search does not delete the old index until the updated index is ready for use. Once the status returns to Active, the modified index is ready to use.

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index using the Atlas UI:

1. In Atlas, go to the Search & Vector Search page for your cluster.

   You can go the MongoDB Search page from the Search & Vector Search option, or the Data Explorer.

   ### Search & Vector Search

   If it's not already displayed, select the organization that contains your project from the  Organizations menu in the navigation bar.

   If it's not already displayed, select your project from the Projects menu in the navigation bar.

   In the sidebar, click Search & Vector Search under the Database heading.

   - If you have no clusters, click Create cluster to create one. To learn more, see [Create an Atlas Infinite or Atlas Core Cluster.](https://www.mongodb.com/docs/atlas/tutorial/create-new-cluster.md#std-label-create-new-cluster)

   - If your project has multiple clusters, select the cluster you want to use from the Select cluster dropdown, then click Go to Search.

   The [Search & Vector Search](https://cloud.mongodb.com/go?l=https%3A%2F%2Fcloud.mongodb.com%2Fv2%2F%3Cproject%3E%23%2Fclusters%2FatlasSearch%2F%3Ccluster%3E) page displays.

2. Click the ... button.

   The ellipsis button is located on the right side of the panel. Click the button beside your desired index and select Delete Index.

3. Click the Delete Index button.

## Considerations for MongoDB Search Indexes

When creating and managing MongoDB Search indexes, consider the following:

### Index Consistency and Rebuilding

#### When is query data consistent after updates?

If you make changes to the collection for which you defined MongoDB Search indexes, the latest data might not be available immediately for queries. However, `mongot` monitors the change streams, which allows it to update stored copies of data, and MongoDB Search indexes are eventually consistent.

When you change an index definition, `mongot` automatically rebuilds the new index in the background, while continuing to serve queries with the old index to make sure there is no downtime. It is recommended that you wait for the index build to complete before running any queries using new index definitions. Using the new index during its build process can lead to unexpected results or incomplete data. This happens when you deploy `mongot` and `mongod` processes on the same node and when you deploy the processes on different nodes. Atlas also rebuilds indexes when you enable or disable [Encryption at Rest.](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption)

If you change the topology of your search deployment, MongoDB Search provisions and builds indexes on any new nodes before removing old nodes, to ensure there is no query downtime.

For deployments where both the `mongod` and `mongot` processes run on the same node, if MongoDB Search introduces changes that require rebuilding your indexes (such as some MongoDB Search features that require an [index update](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-index-rebuild)), Atlas automatically deploys additional nodes for free to build the indexes, while the old nodes continue to serve your queries.

WARNING: If you shard a collection that already has a MongoDB Search index, you might experience a brief period of incomplete search results while the index is building on a shard. Also, if you add a shard for an already sharded collection that contains a MongoDB Search index, your search queries against that collection might return incomplete results until the initial sync process completes on the added shards. To learn more, see [initial sync process.](https://www.mongodb.com/docs/search/performance/index-performance.md#std-label-troubleshoot-initial-sync)

IMPORTANT: If you use the [$out](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/) aggregation stage to modify a collection with an existing MongoDB Search index, you must delete and re-create the search index. If possible, consider using [$merge](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/) instead of `$out`.

### Dedicated Search Nodes

#### How are MongoDB Search indexes affected by dedicated Search Node architecture?

You can deploy [dedicated Search Nodes](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-what-is-search-node) to improve performance, scalability, and resource isolation.

If you've deployed Search Nodes, consider the following:

- Adding and adjusting [shards](https://www.mongodb.com/docs/manual/sharding.md#std-label-sharding-background) triggers a rebuild of the MongoDB Search index. During this index rebuild, the index might not have the most current data. Therefore, queries against data on those shards might fail or return incorrect results.

- If you [reshard](https://www.mongodb.com/docs/manual/core/sharding-reshard-a-collection.md#std-label-sharding-resharding) a collection with MongoDB Search indexes, MongoDB Search indexes on the collection become unavailable when the resharding operation completes. You *must* manually rebuild the MongoDB Search indexes once the operation completes.

- If you issue the command to [change the primary shard](https://www.mongodb.com/docs/manual/reference/command/movePrimary/) of a database, the MongoDB Search indexes for any unsharded collection under this database become unavailable once the operation completes. You *must* delete and create new MongoDB Search indexes once the [`movePrimary`](https://www.mongodb.com/docs/manual/reference/command/movePrimary.md#mongodb-dbcommand-dbcmd.movePrimary) operation is complete.

- Scaling your cluster by adding search nodes or by changing the search tier triggers a rebuild of the full MongoDB Search index. However, if your cluster has dedicated search nodes for which you haven't enabled [Encryption at Rest using Customer Key Management](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption), Atlas provides the following optimizations:

  - When you scale your search nodes, Atlas uses a recent copy of your index in S3 (Simple Storage Service), Google Cloud Storage, or Azure Blob Storage instead of rebuilding the entire MongoDB Search index on the new node.

  - For existing nodes, Atlas periodically takes and uploads a new incremental list of index files. Atlas retains index files for up to fourteen (14) days.

To learn more about MongoDB Search node architecture, see [MongoDB Search Deployment Options.](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-fts-deployment-options)

### Disk, Memory, and Resource Usage

#### How do MongoDB Search indexes affect your available disk space and memory?

Although the data stored on MongoDB Search isn't an identical copy of data from the collection on your Atlas cluster, MongoDB Search indexes still take some disk space and memory. If you enable the `store` option for fields that contain [string](https://www.mongodb.com/docs/search/indexes/field-types/string-type.md#std-label-bson-data-types-string) values or if you configure the [stored source fields](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition) in your index, MongoDB Search stores an identical copy of the specified fields on disk, which can take disk space.

**Important:**

If your collection contains documents that are 16MB (BSON (Binary Javascript Object Notation) limit), MongoDB Search fails to index the document, causes your index to become [STALE](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-index-statuses), and requires a full index rebuild. This issue can also occur when update operations on documents cause the change stream event to exceed the 16MB BSON (Binary Javascript Object Notation) limit. To minimize the risk of your index becoming stale, ensure that documents in your collection don't exceed 8MB. If your index has become stale, you must delete the large document(s) from your collection in order for the index rebuild to complete.

In addition:

- Structure your documents to minimize the size of sub-documents or arrays.

- Avoid operations that update or replace large fields, sub-documents, or arrays.

To learn more, see [Change Streams Production Recommendations](https://www.mongodb.com/docs/manual/administration/change-streams-production-recommendations/) and [Reduce the Size of Large Documents.](https://www.mongodb.com/docs/ops-manager/current/schema-advisor/reduce-document-size/)

### Concurrent Requests Error

#### What happens if there are too many concurrent MongoDB Search index management requests?

If there are too many concurrent index creation or other index management operation requests, MongoDB Search returns the following error:

```shell
Too many concurrent requests. Please try again later.
```

We recommend trying again after some time.

## Create a MongoDB Search Index

To create a MongoDB Search index using the Atlas Administration API:

1. Send a `POST` request.

   Send a `POST` request to the `search/indexes` [endpoint.](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-creategroupclustersearchindex)

   **Note:**

   This `curl` command uses a service account access token ([OAuth 2.0](https://oauth.net/2/)) to authenticate instead of API keys. To learn more, see [Get Started with the Atlas Administration API.](https://www.mongodb.com/docs/atlas/configure-api-access.md#std-label-atlas-admin-api-access)

   ```sh
   curl --header "Authorization: Bearer {ACCESS-TOKEN}" \
     --header "Accept: application/json" \
     --header "Content-Type: application/json" \
     --include \
     --request POST "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/indexes" \
     --data '
          {
          "collectionName": "<collection-name>",
          "database": "<database-name>",
          "name": "<index-name>",
          "type": "search",
          "definition":
          {
              "analyzer": "<analyzer-name>",
              "searchAnalyzer": "<analyzer-name>",
              "mappings": {
              "dynamic": <boolean>,
              "fields": { <field-definition> }
              },
              "numPartitions": <integer>,
              "analyzers": [ {
                  <custom-analyzer-definition>
              }
              ],
              "storedSource": <boolean> | {
              <stored-source-definition>
              },
              "synonyms": [
              {
                  <synonym-mapping-definition>
              }
              ]
          }
        }'
   ```

   To learn more about the syntax and parameters for this endpoint, see [Create One.](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-creategroupclustersearchindex)

2. Review the response.

   IMPORTANT: Atlas doesn't create the index if the collection doesn't exist, but it still returns a `200` status.

## View MongoDB Search Indexes

To retrieve a MongoDB Search index using the Atlas Administration API:

1. Send a `GET` request.

   Send a `GET` request with either the unique ID or name of the MongoDB Search index that you wish to retrieve to the `search/indexes/` endpoint.

   **Note:**

   This `curl` command uses a service account access token ([OAuth 2.0](https://oauth.net/2/)) to authenticate instead of API keys. To learn more, see [Get Started with the Atlas Administration API.](https://www.mongodb.com/docs/atlas/configure-api-access.md#std-label-atlas-admin-api-access)

   ```sh
   curl --header "Authorization: Bearer {ACCESS-TOKEN}" \
   --header "Accept: application/json" \
   --include \
   --request GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/indexes/{indexId}"
   ```

   To learn more about the syntax and parameters for either endpoint, see [Get One By Name](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-getgroupclustersearchindexbyname) and [Get One By ID.](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-getgroupclustersearchindex)

2. Review the response.

To retrieve all MongoDB Search indexes for a collection:

1. Send a `GET` request.

   Send a `GET` request to the `search/indexes/` [endpoint](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-listgroupclustersearchindexes) with the name of the collection whose indexes you want to retrieve.

   ```sh
   curl --header "Authorization: Bearer {ACCESS-TOKEN}" \
   --header "Accept: application/json" \
   --include \
   --request GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/indexes/{databaseName}/{collectionName}"
   ```

2. Review the response.

To retrieve all MongoDB Search indexes for a cluster:

1. Send a `GET` request.

   Send a `GET` request to the `search/indexes/` [endpoint](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-listgroupclustersearchindexes) with the name of the cluster whose indexes you want to retrieve.

   ```sh
   curl --header "Authorization: Bearer {ACCESS-TOKEN}" \
   --header "Accept: application/json" \
   --include \
   --request GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/indexes"
   ```

2. Review the response.

## Edit a MongoDB Search Index

To edit a MongoDB Search index using the Atlas Administration API:

1. Send a `PATCH` request.

   Send a `PATCH` request with either the unique ID or name of the MongoDB Search index that you wish to modify to the `search/indexes/` endpoint.

   **Note:**

   This `curl` command uses a service account access token ([OAuth 2.0](https://oauth.net/2/)) to authenticate instead of API keys. To learn more, see [Get Started with the Atlas Administration API.](https://www.mongodb.com/docs/atlas/configure-api-access.md#std-label-atlas-admin-api-access)

   ```sh
   curl --header "Authorization: Bearer {ACCESS-TOKEN}" \
   --header "Accept: application/json" \
   --header "Content-Type: application/json" \
   --include \
   --request PATCH "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/indexes/{indexId}" \
   --data '
     {
       "definition":
       {
         "analyzer": "lucene.<analyzer>",
         "analyzers": [
           {
             "charFilters": [ ... ],
             "name": "string",
             "tokenFilters": [ ... ],
             "tokenizer": { ... }
           }
         ],
         "mappings": {
           "dynamic": true | false,
           "fields": {
             "property1": {},
             ...
           }
         },
         "searchAnalyzer": "<analyzer-name>",
         "storedSource": {
           "include | exclude": [...]
         },
         "synonyms": [
           {
             <synonym-mapping-definition>
             }
           }
         ]
       }
     }'
   ```

   To learn more about the syntax and parameters for either endpoint, see [Update One By Name](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-updategroupclustersearchindexbyname) and [Update One By ID.](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-updategroupclustersearchindex)

2. Review the response.

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index using the Atlas Administration API:

1. Send a `DELETE` request.

   Send a `DELETE` request with either the unique ID or name of the MongoDB Search index that you wish to delete to the `search/indexes/` endpoint.

   **Note:**

   This `curl` command uses a service account access token ([OAuth 2.0](https://oauth.net/2/)) to authenticate instead of API keys. To learn more, see [Get Started with the Atlas Administration API.](https://www.mongodb.com/docs/atlas/configure-api-access.md#std-label-atlas-admin-api-access)

   ```sh
   curl --header "Authorization: Bearer {ACCESS-TOKEN}" \
   --header "Accept: application/json" \
   --include \
   --request DELETE "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/search/indexes/{indexId}"
   ```

   To learn more about the syntax and parameters for either endpoint, see [Delete One By Name](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-deletegroupclustersearchindexbyname) and [Delete One By ID.](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-deletegroupclustersearchindex)

2. Review the response.

## Considerations for MongoDB Search Indexes

When creating and managing MongoDB Search indexes, consider the following:

### Index Consistency and Rebuilding

#### When is query data consistent after updates?

If you make changes to the collection for which you defined MongoDB Search indexes, the latest data might not be available immediately for queries. However, `mongot` monitors the change streams, which allows it to update stored copies of data, and MongoDB Search indexes are eventually consistent.

When you change an index definition, `mongot` automatically rebuilds the new index in the background, while continuing to serve queries with the old index to make sure there is no downtime. It is recommended that you wait for the index build to complete before running any queries using new index definitions. Using the new index during its build process can lead to unexpected results or incomplete data. This happens when you deploy `mongot` and `mongod` processes on the same node and when you deploy the processes on different nodes. Atlas also rebuilds indexes when you enable or disable [Encryption at Rest.](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption)

If you change the topology of your search deployment, MongoDB Search provisions and builds indexes on any new nodes before removing old nodes, to ensure there is no query downtime.

For deployments where both the `mongod` and `mongot` processes run on the same node, if MongoDB Search introduces changes that require rebuilding your indexes (such as some MongoDB Search features that require an [index update](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-index-rebuild)), Atlas automatically deploys additional nodes for free to build the indexes, while the old nodes continue to serve your queries.

WARNING: If you shard a collection that already has a MongoDB Search index, you might experience a brief period of incomplete search results while the index is building on a shard. Also, if you add a shard for an already sharded collection that contains a MongoDB Search index, your search queries against that collection might return incomplete results until the initial sync process completes on the added shards. To learn more, see [initial sync process.](https://www.mongodb.com/docs/search/performance/index-performance.md#std-label-troubleshoot-initial-sync)

IMPORTANT: If you use the [$out](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/) aggregation stage to modify a collection with an existing MongoDB Search index, you must delete and re-create the search index. If possible, consider using [$merge](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/) instead of `$out`.

### Dedicated Search Nodes

#### How are MongoDB Search indexes affected by dedicated Search Node architecture?

You can deploy [dedicated Search Nodes](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-what-is-search-node) to improve performance, scalability, and resource isolation.

If you've deployed Search Nodes, consider the following:

- Adding and adjusting [shards](https://www.mongodb.com/docs/manual/sharding.md#std-label-sharding-background) triggers a rebuild of the MongoDB Search index. During this index rebuild, the index might not have the most current data. Therefore, queries against data on those shards might fail or return incorrect results.

- If you [reshard](https://www.mongodb.com/docs/manual/core/sharding-reshard-a-collection.md#std-label-sharding-resharding) a collection with MongoDB Search indexes, MongoDB Search indexes on the collection become unavailable when the resharding operation completes. You *must* manually rebuild the MongoDB Search indexes once the operation completes.

- If you issue the command to [change the primary shard](https://www.mongodb.com/docs/manual/reference/command/movePrimary/) of a database, the MongoDB Search indexes for any unsharded collection under this database become unavailable once the operation completes. You *must* delete and create new MongoDB Search indexes once the [`movePrimary`](https://www.mongodb.com/docs/manual/reference/command/movePrimary.md#mongodb-dbcommand-dbcmd.movePrimary) operation is complete.

- Scaling your cluster by adding search nodes or by changing the search tier triggers a rebuild of the full MongoDB Search index. However, if your cluster has dedicated search nodes for which you haven't enabled [Encryption at Rest using Customer Key Management](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption), Atlas provides the following optimizations:

  - When you scale your search nodes, Atlas uses a recent copy of your index in S3 (Simple Storage Service), Google Cloud Storage, or Azure Blob Storage instead of rebuilding the entire MongoDB Search index on the new node.

  - For existing nodes, Atlas periodically takes and uploads a new incremental list of index files. Atlas retains index files for up to fourteen (14) days.

To learn more about MongoDB Search node architecture, see [MongoDB Search Deployment Options.](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-fts-deployment-options)

### Disk, Memory, and Resource Usage

#### How do MongoDB Search indexes affect your available disk space and memory?

Although the data stored on MongoDB Search isn't an identical copy of data from the collection on your Atlas cluster, MongoDB Search indexes still take some disk space and memory. If you enable the `store` option for fields that contain [string](https://www.mongodb.com/docs/search/indexes/field-types/string-type.md#std-label-bson-data-types-string) values or if you configure the [stored source fields](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition) in your index, MongoDB Search stores an identical copy of the specified fields on disk, which can take disk space.

**Important:**

If your collection contains documents that are 16MB (BSON (Binary Javascript Object Notation) limit), MongoDB Search fails to index the document, causes your index to become [STALE](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-index-statuses), and requires a full index rebuild. This issue can also occur when update operations on documents cause the change stream event to exceed the 16MB BSON (Binary Javascript Object Notation) limit. To minimize the risk of your index becoming stale, ensure that documents in your collection don't exceed 8MB. If your index has become stale, you must delete the large document(s) from your collection in order for the index rebuild to complete.

In addition:

- Structure your documents to minimize the size of sub-documents or arrays.

- Avoid operations that update or replace large fields, sub-documents, or arrays.

To learn more, see [Change Streams Production Recommendations](https://www.mongodb.com/docs/manual/administration/change-streams-production-recommendations/) and [Reduce the Size of Large Documents.](https://www.mongodb.com/docs/ops-manager/current/schema-advisor/reduce-document-size/)

### Concurrent Requests Error

#### What happens if there are too many concurrent MongoDB Search index management requests?

If there are too many concurrent index creation or other index management operation requests, MongoDB Search returns the following error:

```shell
Too many concurrent requests. Please try again later.
```

We recommend trying again after some time.

## Create a MongoDB Search Index

Run the [atlas clusters search indexes create](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-create/) command.

### Example

The following example shows you how to use the `atlas clusters` command to create a MongoDB Search index in non-interactive mode with a configuration file.

1. Create an `indexDef.json` configuration file.

   ```json
   {
     "collectionName": "movies",
     "database": "sample_mflix",
     "definition": {
       "mappings": {
        "dynamic": true
       },
     },
     "name": "searchIndex"
   }
   ```

2. Create a MongoDB Search index.

   Specify the cluster name and run the following command:

   ```sh
   atlas clusters search indexes create --file indexDef.json --clusterName <clusterName>
   ```

## View MongoDB Search Indexes

Run the [atlas clusters search indexes list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas clusters search indexes describe](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-describe/) command.

## Edit a MongoDB Search Index

Run the [atlas clusters search indexes update](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-update/) command.

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

Run the [atlas clusters search indexes delete](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-delete/) command.

## Considerations for MongoDB Search Indexes

When creating and managing MongoDB Search indexes, consider the following:

### Index Consistency and Rebuilding

#### When is query data consistent after updates?

If you make changes to the collection for which you defined MongoDB Search indexes, the latest data might not be available immediately for queries. However, `mongot` monitors the change streams, which allows it to update stored copies of data, and MongoDB Search indexes are eventually consistent.

When you change an index definition, `mongot` automatically rebuilds the new index in the background, while continuing to serve queries with the old index to make sure there is no downtime. It is recommended that you wait for the index build to complete before running any queries using new index definitions. Using the new index during its build process can lead to unexpected results or incomplete data. This happens when you deploy `mongot` and `mongod` processes on the same node and when you deploy the processes on different nodes. Atlas also rebuilds indexes when you enable or disable [Encryption at Rest.](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption)

If you change the topology of your search deployment, MongoDB Search provisions and builds indexes on any new nodes before removing old nodes, to ensure there is no query downtime.

For deployments where both the `mongod` and `mongot` processes run on the same node, if MongoDB Search introduces changes that require rebuilding your indexes (such as some MongoDB Search features that require an [index update](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-index-rebuild)), Atlas automatically deploys additional nodes for free to build the indexes, while the old nodes continue to serve your queries.

WARNING: If you shard a collection that already has a MongoDB Search index, you might experience a brief period of incomplete search results while the index is building on a shard. Also, if you add a shard for an already sharded collection that contains a MongoDB Search index, your search queries against that collection might return incomplete results until the initial sync process completes on the added shards. To learn more, see [initial sync process.](https://www.mongodb.com/docs/search/performance/index-performance.md#std-label-troubleshoot-initial-sync)

IMPORTANT: If you use the [$out](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/) aggregation stage to modify a collection with an existing MongoDB Search index, you must delete and re-create the search index. If possible, consider using [$merge](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/) instead of `$out`.

### Dedicated Search Nodes

#### How are MongoDB Search indexes affected by dedicated Search Node architecture?

You can deploy [dedicated Search Nodes](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-what-is-search-node) to improve performance, scalability, and resource isolation.

If you've deployed Search Nodes, consider the following:

- Adding and adjusting [shards](https://www.mongodb.com/docs/manual/sharding.md#std-label-sharding-background) triggers a rebuild of the MongoDB Search index. During this index rebuild, the index might not have the most current data. Therefore, queries against data on those shards might fail or return incorrect results.

- If you [reshard](https://www.mongodb.com/docs/manual/core/sharding-reshard-a-collection.md#std-label-sharding-resharding) a collection with MongoDB Search indexes, MongoDB Search indexes on the collection become unavailable when the resharding operation completes. You *must* manually rebuild the MongoDB Search indexes once the operation completes.

- If you issue the command to [change the primary shard](https://www.mongodb.com/docs/manual/reference/command/movePrimary/) of a database, the MongoDB Search indexes for any unsharded collection under this database become unavailable once the operation completes. You *must* delete and create new MongoDB Search indexes once the [`movePrimary`](https://www.mongodb.com/docs/manual/reference/command/movePrimary.md#mongodb-dbcommand-dbcmd.movePrimary) operation is complete.

- Scaling your cluster by adding search nodes or by changing the search tier triggers a rebuild of the full MongoDB Search index. However, if your cluster has dedicated search nodes for which you haven't enabled [Encryption at Rest using Customer Key Management](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption), Atlas provides the following optimizations:

  - When you scale your search nodes, Atlas uses a recent copy of your index in S3 (Simple Storage Service), Google Cloud Storage, or Azure Blob Storage instead of rebuilding the entire MongoDB Search index on the new node.

  - For existing nodes, Atlas periodically takes and uploads a new incremental list of index files. Atlas retains index files for up to fourteen (14) days.

To learn more about MongoDB Search node architecture, see [MongoDB Search Deployment Options.](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-fts-deployment-options)

### Disk, Memory, and Resource Usage

#### How do MongoDB Search indexes affect your available disk space and memory?

Although the data stored on MongoDB Search isn't an identical copy of data from the collection on your Atlas cluster, MongoDB Search indexes still take some disk space and memory. If you enable the `store` option for fields that contain [string](https://www.mongodb.com/docs/search/indexes/field-types/string-type.md#std-label-bson-data-types-string) values or if you configure the [stored source fields](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition) in your index, MongoDB Search stores an identical copy of the specified fields on disk, which can take disk space.

**Important:**

If your collection contains documents that are 16MB (BSON (Binary Javascript Object Notation) limit), MongoDB Search fails to index the document, causes your index to become [STALE](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-index-statuses), and requires a full index rebuild. This issue can also occur when update operations on documents cause the change stream event to exceed the 16MB BSON (Binary Javascript Object Notation) limit. To minimize the risk of your index becoming stale, ensure that documents in your collection don't exceed 8MB. If your index has become stale, you must delete the large document(s) from your collection in order for the index rebuild to complete.

In addition:

- Structure your documents to minimize the size of sub-documents or arrays.

- Avoid operations that update or replace large fields, sub-documents, or arrays.

To learn more, see [Change Streams Production Recommendations](https://www.mongodb.com/docs/manual/administration/change-streams-production-recommendations/) and [Reduce the Size of Large Documents.](https://www.mongodb.com/docs/ops-manager/current/schema-advisor/reduce-document-size/)

### Concurrent Requests Error

#### What happens if there are too many concurrent MongoDB Search index management requests?

If there are too many concurrent index creation or other index management operation requests, MongoDB Search returns the following error:

```shell
Too many concurrent requests. Please try again later.
```

We recommend trying again after some time.

## Create a MongoDB Search Index

Run the [atlas deployments search indexes create](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-create/) command.

To learn more about how to use the Atlas CLI to create a local Atlas deployment, see [Create a Local Atlas Deployment.](https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-local/)

**See also: Related Links**

- [Install the Atlas CLI](https://www.mongodb.com/docs/atlas/cli/current/install-atlas-cli/)

- [Connect to the Atlas CLI](https://www.mongodb.com/docs/atlas/cli/current/connect-atlas-cli/)

### Example

The following example shows you how to use the `atlas deployments` command to create a MongoDB Search index in non-interactive mode with a configuration file.

1. Create an `indexDef.json` configuration file.

   ```json
   {
     "collectionName": "movies",
     "database": "sample_mflix",
     "definition": {
       "mappings": {
        "dynamic": true
       },
     },
     "name": "searchIndex"
   }
   ```

2. Create a MongoDB Search index.

   Run the following command:

   ```sh
   atlas deployments search indexes create --file indexDef.json
   ```

## View MongoDB Search Indexes

Run the [atlas deployments search indexes list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/) or [atlas deployments search indexes describe](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-describe/) command.

## Edit a MongoDB Search Index

There is no Atlas CLI command to edit a MongoDB Search index. To edit a MongoDB Search index, you can use a different interface, such as [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh), MongoDB Compass, or a supported driver.

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

Run the [atlas deployments search indexes delete](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-delete/) command.

## Create a MongoDB Search Index

To create a MongoDB Search index using [`mongosh`:](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh)

1. Connect using `mongosh`.

   To learn more, see [Connect to a Cluster via mongosh.](https://www.mongodb.com/docs/atlas/mongo-shell-connection.md#std-label-connect-mongo-shell)

2. Create a MongoDB Search index.

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

   The command has the following syntax. If you omit the index name, MongoDB Search names the index `default`. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

   ```javascript
   db.<collection>.createSearchIndex(
        "<index-name>",
        {
            /* search index definition */
        }
   )
   ```

   For example:

   To create an index named `example-index` that dynamically indexes the fields in the `movies` collection, run the following command:

   ```shell
   db.movies.createSearchIndex(
       "example-index",
       { mappings: { dynamic: true } }
   )
   ```

   **Output:**

   ```text
   example-index
   ```

## View MongoDB Search Indexes

To retrieve your MongoDB Search indexes through [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh), use the [`db.collection.getSearchIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#mongodb-method-db.collection.getSearchIndexes) method.

The command has the following syntax. If you omit the index name, MongoDB Search returns all indexes on the collection.

```javascript
db.<collection>.getSearchIndexes("<index-name>")
```

### Example

The following command retrieves a search index named `default` from the `movies` collection. Your results should resemble the example output:

```shell
db.movies.getSearchIndexes("default")
```

**Output:**

```json
[
   {
      id: '648b4ad4d697b73bf9d2e5e0',
      name: 'default',
      status: 'READY',
      queryable: true,
      latestDefinition: { mappings: { dynamic: true } }
   }
]
```

## Edit a MongoDB Search Index

To edit a MongoDB Search index through [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh), use the [`db.collection.updateSearchIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.updateSearchIndex.md#mongodb-method-db.collection.updateSearchIndex) method.

The command has the following syntax. Specify the name of the index that you want to edit and define the new index definition. This definition replaces the index's existing definition. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

```javascript
db.<collection>.updateSearchIndex(
     "<index-name>",
     /* updated search index definition */
)
```

### Example

The following command updates a search index named `default` from the `movies` collection to use [static mappings:](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings)

```text
db.movies.updateSearchIndex(
    "default",
    {
        "mappings": {
        "dynamic": false,
        "fields": {
            "<field-name>": {
                 "type": "<field-type>"
            }
        }
    }
)
```

**Note:**

The `db.collection.updateSearchIndex()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index through [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh), use the [`db.collection.dropSearchIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropSearchIndex.md#mongodb-method-db.collection.dropSearchIndex) method.

The command has the following syntax:

```javascript
db.<collection>.dropSearchIndex("<index-name>")
```

### Example

The following command deletes a search index named `default` from the `movies` collection:

```javascript
db.movies.dropSearchIndex("default")
```

**Note:**

The `db.collection.dropSearchIndex()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

## Considerations for MongoDB Search Indexes

When creating and managing MongoDB Search indexes, consider the following:

### Index Consistency and Rebuilding

#### When is query data consistent after updates?

If you make changes to the collection for which you defined MongoDB Search indexes, the latest data might not be available immediately for queries. However, `mongot` monitors the change streams, which allows it to update stored copies of data, and MongoDB Search indexes are eventually consistent.

When you change an index definition, `mongot` automatically rebuilds the new index in the background, while continuing to serve queries with the old index to make sure there is no downtime. It is recommended that you wait for the index build to complete before running any queries using new index definitions. Using the new index during its build process can lead to unexpected results or incomplete data. This happens when you deploy `mongot` and `mongod` processes on the same node and when you deploy the processes on different nodes. Atlas also rebuilds indexes when you enable or disable [Encryption at Rest.](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption)

If you change the topology of your search deployment, MongoDB Search provisions and builds indexes on any new nodes before removing old nodes, to ensure there is no query downtime.

For deployments where both the `mongod` and `mongot` processes run on the same node, if MongoDB Search introduces changes that require rebuilding your indexes (such as some MongoDB Search features that require an [index update](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-index-rebuild)), Atlas automatically deploys additional nodes for free to build the indexes, while the old nodes continue to serve your queries.

WARNING: If you shard a collection that already has a MongoDB Search index, you might experience a brief period of incomplete search results while the index is building on a shard. Also, if you add a shard for an already sharded collection that contains a MongoDB Search index, your search queries against that collection might return incomplete results until the initial sync process completes on the added shards. To learn more, see [initial sync process.](https://www.mongodb.com/docs/search/performance/index-performance.md#std-label-troubleshoot-initial-sync)

IMPORTANT: If you use the [$out](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/) aggregation stage to modify a collection with an existing MongoDB Search index, you must delete and re-create the search index. If possible, consider using [$merge](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/) instead of `$out`.

### Dedicated Search Nodes

#### How are MongoDB Search indexes affected by dedicated Search Node architecture?

You can deploy [dedicated Search Nodes](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-what-is-search-node) to improve performance, scalability, and resource isolation.

If you've deployed Search Nodes, consider the following:

- Adding and adjusting [shards](https://www.mongodb.com/docs/manual/sharding.md#std-label-sharding-background) triggers a rebuild of the MongoDB Search index. During this index rebuild, the index might not have the most current data. Therefore, queries against data on those shards might fail or return incorrect results.

- If you [reshard](https://www.mongodb.com/docs/manual/core/sharding-reshard-a-collection.md#std-label-sharding-resharding) a collection with MongoDB Search indexes, MongoDB Search indexes on the collection become unavailable when the resharding operation completes. You *must* manually rebuild the MongoDB Search indexes once the operation completes.

- If you issue the command to [change the primary shard](https://www.mongodb.com/docs/manual/reference/command/movePrimary/) of a database, the MongoDB Search indexes for any unsharded collection under this database become unavailable once the operation completes. You *must* delete and create new MongoDB Search indexes once the [`movePrimary`](https://www.mongodb.com/docs/manual/reference/command/movePrimary.md#mongodb-dbcommand-dbcmd.movePrimary) operation is complete.

- Scaling your cluster by adding search nodes or by changing the search tier triggers a rebuild of the full MongoDB Search index. However, if your cluster has dedicated search nodes for which you haven't enabled [Encryption at Rest using Customer Key Management](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption), Atlas provides the following optimizations:

  - When you scale your search nodes, Atlas uses a recent copy of your index in S3 (Simple Storage Service), Google Cloud Storage, or Azure Blob Storage instead of rebuilding the entire MongoDB Search index on the new node.

  - For existing nodes, Atlas periodically takes and uploads a new incremental list of index files. Atlas retains index files for up to fourteen (14) days.

To learn more about MongoDB Search node architecture, see [MongoDB Search Deployment Options.](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-fts-deployment-options)

### Disk, Memory, and Resource Usage

#### How do MongoDB Search indexes affect your available disk space and memory?

Although the data stored on MongoDB Search isn't an identical copy of data from the collection on your Atlas cluster, MongoDB Search indexes still take some disk space and memory. If you enable the `store` option for fields that contain [string](https://www.mongodb.com/docs/search/indexes/field-types/string-type.md#std-label-bson-data-types-string) values or if you configure the [stored source fields](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition) in your index, MongoDB Search stores an identical copy of the specified fields on disk, which can take disk space.

**Important:**

If your collection contains documents that are 16MB (BSON (Binary Javascript Object Notation) limit), MongoDB Search fails to index the document, causes your index to become [STALE](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-index-statuses), and requires a full index rebuild. This issue can also occur when update operations on documents cause the change stream event to exceed the 16MB BSON (Binary Javascript Object Notation) limit. To minimize the risk of your index becoming stale, ensure that documents in your collection don't exceed 8MB. If your index has become stale, you must delete the large document(s) from your collection in order for the index rebuild to complete.

In addition:

- Structure your documents to minimize the size of sub-documents or arrays.

- Avoid operations that update or replace large fields, sub-documents, or arrays.

To learn more, see [Change Streams Production Recommendations](https://www.mongodb.com/docs/manual/administration/change-streams-production-recommendations/) and [Reduce the Size of Large Documents.](https://www.mongodb.com/docs/ops-manager/current/schema-advisor/reduce-document-size/)

### Concurrent Requests Error

#### What happens if there are too many concurrent MongoDB Search index management requests?

If there are too many concurrent index creation or other index management operation requests, MongoDB Search returns the following error:

```shell
Too many concurrent requests. Please try again later.
```

We recommend trying again after some time.

## Create a MongoDB Search Index

To create a MongoDB Search index using [`mongosh`:](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh)

1. Connect using `mongosh`.

   To learn more, see [Connect to a Cluster via mongosh.](https://www.mongodb.com/docs/atlas/mongo-shell-connection.md#std-label-connect-mongo-shell)

2. Create a MongoDB Search index.

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

   The command has the following syntax. If you omit the index name, MongoDB Search names the index `default`. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

   ```javascript
   db.<collection>.createSearchIndex(
        "<index-name>",
        {
            /* search index definition */
        }
   )
   ```

   For example:

   To create an index named `example-index` that dynamically indexes the fields in the `movies` collection, run the following command:

   ```shell
   db.movies.createSearchIndex(
       "example-index",
       { mappings: { dynamic: true } }
   )
   ```

   **Output:**

   ```text
   example-index
   ```

## View MongoDB Search Indexes

To retrieve your MongoDB Search indexes through [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh), use the [`db.collection.getSearchIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#mongodb-method-db.collection.getSearchIndexes) method.

The command has the following syntax. If you omit the index name, MongoDB Search returns all indexes on the collection.

```javascript
db.<collection>.getSearchIndexes("<index-name>")
```

### Example

The following command retrieves a search index named `default` from the `movies` collection. Your results should resemble the example output:

```shell
db.movies.getSearchIndexes("default")
```

**Output:**

```json
[
   {
      id: '648b4ad4d697b73bf9d2e5e0',
      name: 'default',
      status: 'READY',
      queryable: true,
      latestDefinition: { mappings: { dynamic: true } }
   }
]
```

## Edit a MongoDB Search Index

To edit a MongoDB Search index through [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh), use the [`db.collection.updateSearchIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.updateSearchIndex.md#mongodb-method-db.collection.updateSearchIndex) method.

The command has the following syntax. Specify the name of the index that you want to edit and define the new index definition. This definition replaces the index's existing definition. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

```javascript
db.<collection>.updateSearchIndex(
     "<index-name>",
     /* updated search index definition */
)
```

### Example

The following command updates a search index named `default` from the `movies` collection to use [static mappings:](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings)

```text
db.movies.updateSearchIndex(
    "default",
    {
        "mappings": {
        "dynamic": false,
        "fields": {
            "<field-name>": {
                 "type": "<field-type>"
            }
        }
    }
)
```

**Note:**

The `db.collection.updateSearchIndex()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index through [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh), use the [`db.collection.dropSearchIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropSearchIndex.md#mongodb-method-db.collection.dropSearchIndex) method.

The command has the following syntax:

```javascript
db.<collection>.dropSearchIndex("<index-name>")
```

### Example

The following command deletes a search index named `default` from the `movies` collection:

```javascript
db.movies.dropSearchIndex("default")
```

**Note:**

The `db.collection.dropSearchIndex()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

## Create a MongoDB Search Index

To create a MongoDB Search index using [`mongosh`:](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh)

1. Connect using `mongosh`.

   To learn more, see [Connect to a Cluster via mongosh.](https://www.mongodb.com/docs/atlas/mongo-shell-connection.md#std-label-connect-mongo-shell)

2. Create a MongoDB Search index.

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

   The command has the following syntax. If you omit the index name, MongoDB Search names the index `default`. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

   ```javascript
   db.<collection>.createSearchIndex(
        "<index-name>",
        {
            /* search index definition */
        }
   )
   ```

   For example:

   To create an index named `example-index` that dynamically indexes the fields in the `movies` collection, run the following command:

   ```shell
   db.movies.createSearchIndex(
       "example-index",
       { mappings: { dynamic: true } }
   )
   ```

   **Output:**

   ```text
   example-index
   ```

## View MongoDB Search Indexes

To retrieve your MongoDB Search indexes through [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh), use the [`db.collection.getSearchIndexes()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#mongodb-method-db.collection.getSearchIndexes) method.

The command has the following syntax. If you omit the index name, MongoDB Search returns all indexes on the collection.

```javascript
db.<collection>.getSearchIndexes("<index-name>")
```

### Example

The following command retrieves a search index named `default` from the `movies` collection. Your results should resemble the example output:

```shell
db.movies.getSearchIndexes("default")
```

**Output:**

```json
[
   {
      id: '648b4ad4d697b73bf9d2e5e0',
      name: 'default',
      status: 'READY',
      queryable: true,
      latestDefinition: { mappings: { dynamic: true } }
   }
]
```

## Edit a MongoDB Search Index

To edit a MongoDB Search index through [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh), use the [`db.collection.updateSearchIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.updateSearchIndex.md#mongodb-method-db.collection.updateSearchIndex) method.

The command has the following syntax. Specify the name of the index that you want to edit and define the new index definition. This definition replaces the index's existing definition. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

```javascript
db.<collection>.updateSearchIndex(
     "<index-name>",
     /* updated search index definition */
)
```

### Example

The following command updates a search index named `default` from the `movies` collection to use [static mappings:](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings)

```text
db.movies.updateSearchIndex(
    "default",
    {
        "mappings": {
        "dynamic": false,
        "fields": {
            "<field-name>": {
                 "type": "<field-type>"
            }
        }
    }
)
```

**Note:**

The `db.collection.updateSearchIndex()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index through [`mongosh`](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh), use the [`db.collection.dropSearchIndex()`](https://www.mongodb.com/docs/manual/reference/method/db.collection.dropSearchIndex.md#mongodb-method-db.collection.dropSearchIndex) method.

The command has the following syntax:

```javascript
db.<collection>.dropSearchIndex("<index-name>")
```

### Example

The following command deletes a search index named `default` from the `movies` collection:

```javascript
db.movies.dropSearchIndex("default")
```

**Note:**

The `db.collection.dropSearchIndex()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

## Create a MongoDB Search Index

To create a MongoDB Search index using MongoDB Compass:

1. Connect to your cluster via MongoDB Compass.

   Open [Compass](https://www.mongodb.com/try/download/compass) and connect to your cluster. For detailed instructions, see [Connect to a Cluster via Compass.](https://www.mongodb.com/docs/atlas/compass-connection.md#std-label-atlas-connect-via-compass)

2. Specify the database and collection.

   On the Database screen, click the name of the database, then click the name of the collection.

3. Create the MongoDB Search index.

   Click the Indexes tab, then select Search Indexes.

   Click Create Index to open the index creation dialog box.

   Specify a name for the index.

   Your MongoDB Search index is named `default` by default. If you keep this name, then your index will be the default Search index for any MongoDB Search query that does not specify a different `index` option in its [operators](https://www.mongodb.com/docs/search/query/operators-collectors/overview.md#std-label-fts-operators). If you are creating multiple indexes, we recommend that you maintain a consistent, descriptive naming convention across your indexes.

   Specify the JSON (Javascript Object Notation) MongoDB Search index definition.

   ```json
   {
     "mappings": { 
       "dynamic": true|false, 
       "fields": { 
         "<field-name>": {
           "type": "string",
           "analyzer": "<atlas-search-analyzer>",
           "searchAnalyzer": "<atlas-search-analyzer>",
           "indexOptions": "docs|freqs|positions|offsets",
           "store": true|false,
           "ignoreAbove": <integer>,
           "similarity": { "type": "bm25|boolean|stableTfl" },
           "multi": { <string-field-definition> },
           "norms": "include|omit"
         }
       } 
     }
   }
   ```

   Click Create Search Index.

## View MongoDB Search Indexes

To view your MongoDB Search indexes on a collection using MongoDB Compass:

1. Connect to your cluster via MongoDB Compass.

   Open [Compass](https://www.mongodb.com/try/download/compass) and connect to your cluster. For detailed instructions, see [Connect to a Cluster via Compass.](https://www.mongodb.com/docs/atlas/compass-connection.md#std-label-atlas-connect-via-compass)

2. Specify the database and collection.

   On the Database screen, click the name of the database, then click the name of the collection.

3. Click the Indexes tab, then Search Indexes.

   The page displays the following:

   | Column Name | Description |
   | --- | --- |
   | Name and Fields | Name of the index and and the name of the indexed fields. |
   | Type | Type of index. Value can be `Search` or `Vector Search`. |
   | Status | Status of the index. To learn more, see [MongoDB Search Index Statuses.](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status) |
   | Actions | Actions you can perform on the index when you hover over the index. You can take the following actions: Aggregate - to switch to the Aggregations tab to run queries using the index.;  - to edit the index in raw JSON (Javascript Object Notation) format.;  - to delete the index. |

## Edit a MongoDB Search Index

To edit a MongoDB Search index using MongoDB Compass:

1. From the Indexes tab, click Search Indexes.

2. Hover over the index you want to edit.

3. Click the pencil icon to open the Edit dialog.

4. Make the changes and click Save.

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index using MongoDB Compass:

1. From the Indexes tab, click Search Indexes.

2. Hover over the index you want to delete.

3. Click the trash icon to open the confirmation dialog.

4. Type the name of the index you want to delete and click Save.

## Considerations for MongoDB Search Indexes

When creating and managing MongoDB Search indexes, consider the following:

### Index Consistency and Rebuilding

#### When is query data consistent after updates?

If you make changes to the collection for which you defined MongoDB Search indexes, the latest data might not be available immediately for queries. However, `mongot` monitors the change streams, which allows it to update stored copies of data, and MongoDB Search indexes are eventually consistent.

When you change an index definition, `mongot` automatically rebuilds the new index in the background, while continuing to serve queries with the old index to make sure there is no downtime. It is recommended that you wait for the index build to complete before running any queries using new index definitions. Using the new index during its build process can lead to unexpected results or incomplete data. This happens when you deploy `mongot` and `mongod` processes on the same node and when you deploy the processes on different nodes. Atlas also rebuilds indexes when you enable or disable [Encryption at Rest.](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption)

If you change the topology of your search deployment, MongoDB Search provisions and builds indexes on any new nodes before removing old nodes, to ensure there is no query downtime.

For deployments where both the `mongod` and `mongot` processes run on the same node, if MongoDB Search introduces changes that require rebuilding your indexes (such as some MongoDB Search features that require an [index update](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-index-rebuild)), Atlas automatically deploys additional nodes for free to build the indexes, while the old nodes continue to serve your queries.

WARNING: If you shard a collection that already has a MongoDB Search index, you might experience a brief period of incomplete search results while the index is building on a shard. Also, if you add a shard for an already sharded collection that contains a MongoDB Search index, your search queries against that collection might return incomplete results until the initial sync process completes on the added shards. To learn more, see [initial sync process.](https://www.mongodb.com/docs/search/performance/index-performance.md#std-label-troubleshoot-initial-sync)

IMPORTANT: If you use the [$out](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/) aggregation stage to modify a collection with an existing MongoDB Search index, you must delete and re-create the search index. If possible, consider using [$merge](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/) instead of `$out`.

### Dedicated Search Nodes

#### How are MongoDB Search indexes affected by dedicated Search Node architecture?

You can deploy [dedicated Search Nodes](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-what-is-search-node) to improve performance, scalability, and resource isolation.

If you've deployed Search Nodes, consider the following:

- Adding and adjusting [shards](https://www.mongodb.com/docs/manual/sharding.md#std-label-sharding-background) triggers a rebuild of the MongoDB Search index. During this index rebuild, the index might not have the most current data. Therefore, queries against data on those shards might fail or return incorrect results.

- If you [reshard](https://www.mongodb.com/docs/manual/core/sharding-reshard-a-collection.md#std-label-sharding-resharding) a collection with MongoDB Search indexes, MongoDB Search indexes on the collection become unavailable when the resharding operation completes. You *must* manually rebuild the MongoDB Search indexes once the operation completes.

- If you issue the command to [change the primary shard](https://www.mongodb.com/docs/manual/reference/command/movePrimary/) of a database, the MongoDB Search indexes for any unsharded collection under this database become unavailable once the operation completes. You *must* delete and create new MongoDB Search indexes once the [`movePrimary`](https://www.mongodb.com/docs/manual/reference/command/movePrimary.md#mongodb-dbcommand-dbcmd.movePrimary) operation is complete.

- Scaling your cluster by adding search nodes or by changing the search tier triggers a rebuild of the full MongoDB Search index. However, if your cluster has dedicated search nodes for which you haven't enabled [Encryption at Rest using Customer Key Management](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption), Atlas provides the following optimizations:

  - When you scale your search nodes, Atlas uses a recent copy of your index in S3 (Simple Storage Service), Google Cloud Storage, or Azure Blob Storage instead of rebuilding the entire MongoDB Search index on the new node.

  - For existing nodes, Atlas periodically takes and uploads a new incremental list of index files. Atlas retains index files for up to fourteen (14) days.

To learn more about MongoDB Search node architecture, see [MongoDB Search Deployment Options.](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-fts-deployment-options)

### Disk, Memory, and Resource Usage

#### How do MongoDB Search indexes affect your available disk space and memory?

Although the data stored on MongoDB Search isn't an identical copy of data from the collection on your Atlas cluster, MongoDB Search indexes still take some disk space and memory. If you enable the `store` option for fields that contain [string](https://www.mongodb.com/docs/search/indexes/field-types/string-type.md#std-label-bson-data-types-string) values or if you configure the [stored source fields](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition) in your index, MongoDB Search stores an identical copy of the specified fields on disk, which can take disk space.

**Important:**

If your collection contains documents that are 16MB (BSON (Binary Javascript Object Notation) limit), MongoDB Search fails to index the document, causes your index to become [STALE](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-index-statuses), and requires a full index rebuild. This issue can also occur when update operations on documents cause the change stream event to exceed the 16MB BSON (Binary Javascript Object Notation) limit. To minimize the risk of your index becoming stale, ensure that documents in your collection don't exceed 8MB. If your index has become stale, you must delete the large document(s) from your collection in order for the index rebuild to complete.

In addition:

- Structure your documents to minimize the size of sub-documents or arrays.

- Avoid operations that update or replace large fields, sub-documents, or arrays.

To learn more, see [Change Streams Production Recommendations](https://www.mongodb.com/docs/manual/administration/change-streams-production-recommendations/) and [Reduce the Size of Large Documents.](https://www.mongodb.com/docs/ops-manager/current/schema-advisor/reduce-document-size/)

### Concurrent Requests Error

#### What happens if there are too many concurrent MongoDB Search index management requests?

If there are too many concurrent index creation or other index management operation requests, MongoDB Search returns the following error:

```shell
Too many concurrent requests. Please try again later.
```

We recommend trying again after some time.

## Create a MongoDB Search Index

To create a MongoDB Search index using MongoDB Compass:

1. Connect to your cluster via MongoDB Compass.

   Open [Compass](https://www.mongodb.com/try/download/compass) and connect to your cluster. For detailed instructions, see [Connect to a Cluster via Compass.](https://www.mongodb.com/docs/atlas/compass-connection.md#std-label-atlas-connect-via-compass)

2. Specify the database and collection.

   On the Database screen, click the name of the database, then click the name of the collection.

3. Create the MongoDB Search index.

   Click the Indexes tab, then select Search Indexes.

   Click Create Index to open the index creation dialog box.

   Specify a name for the index.

   Your MongoDB Search index is named `default` by default. If you keep this name, then your index will be the default Search index for any MongoDB Search query that does not specify a different `index` option in its [operators](https://www.mongodb.com/docs/search/query/operators-collectors/overview.md#std-label-fts-operators). If you are creating multiple indexes, we recommend that you maintain a consistent, descriptive naming convention across your indexes.

   Specify the JSON (Javascript Object Notation) MongoDB Search index definition.

   ```json
   {
     "mappings": { 
       "dynamic": true|false, 
       "fields": { 
         "<field-name>": {
           "type": "string",
           "analyzer": "<atlas-search-analyzer>",
           "searchAnalyzer": "<atlas-search-analyzer>",
           "indexOptions": "docs|freqs|positions|offsets",
           "store": true|false,
           "ignoreAbove": <integer>,
           "similarity": { "type": "bm25|boolean|stableTfl" },
           "multi": { <string-field-definition> },
           "norms": "include|omit"
         }
       } 
     }
   }
   ```

   Click Create Search Index.

## View MongoDB Search Indexes

To view your MongoDB Search indexes on a collection using MongoDB Compass:

1. Connect to your cluster via MongoDB Compass.

   Open [Compass](https://www.mongodb.com/try/download/compass) and connect to your cluster. For detailed instructions, see [Connect to a Cluster via Compass.](https://www.mongodb.com/docs/atlas/compass-connection.md#std-label-atlas-connect-via-compass)

2. Specify the database and collection.

   On the Database screen, click the name of the database, then click the name of the collection.

3. Click the Indexes tab, then Search Indexes.

   The page displays the following:

   | Column Name | Description |
   | --- | --- |
   | Name and Fields | Name of the index and and the name of the indexed fields. |
   | Type | Type of index. Value can be `Search` or `Vector Search`. |
   | Status | Status of the index. To learn more, see [MongoDB Search Index Statuses.](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status) |
   | Actions | Actions you can perform on the index when you hover over the index. You can take the following actions: Aggregate - to switch to the Aggregations tab to run queries using the index.;  - to edit the index in raw JSON (Javascript Object Notation) format.;  - to delete the index. |

## Edit a MongoDB Search Index

To edit a MongoDB Search index using MongoDB Compass:

1. From the Indexes tab, click Search Indexes.

2. Hover over the index you want to edit.

3. Click the pencil icon to open the Edit dialog.

4. Make the changes and click Save.

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index using MongoDB Compass:

1. From the Indexes tab, click Search Indexes.

2. Hover over the index you want to delete.

3. Click the trash icon to open the confirmation dialog.

4. Type the name of the index you want to delete and click Save.

## Create a MongoDB Search Index

To create a MongoDB Search index using MongoDB Compass:

1. Connect to your cluster via MongoDB Compass.

   Open [Compass](https://www.mongodb.com/try/download/compass) and connect to your cluster. For detailed instructions, see [Connect to a Cluster via Compass.](https://www.mongodb.com/docs/atlas/compass-connection.md#std-label-atlas-connect-via-compass)

2. Specify the database and collection.

   On the Database screen, click the name of the database, then click the name of the collection.

3. Create the MongoDB Search index.

   Click the Indexes tab, then select Search Indexes.

   Click Create Index to open the index creation dialog box.

   Specify a name for the index.

   Your MongoDB Search index is named `default` by default. If you keep this name, then your index will be the default Search index for any MongoDB Search query that does not specify a different `index` option in its [operators](https://www.mongodb.com/docs/search/query/operators-collectors/overview.md#std-label-fts-operators). If you are creating multiple indexes, we recommend that you maintain a consistent, descriptive naming convention across your indexes.

   Specify the JSON (Javascript Object Notation) MongoDB Search index definition.

   ```json
   {
     "mappings": { 
       "dynamic": true|false, 
       "fields": { 
         "<field-name>": {
           "type": "string",
           "analyzer": "<atlas-search-analyzer>",
           "searchAnalyzer": "<atlas-search-analyzer>",
           "indexOptions": "docs|freqs|positions|offsets",
           "store": true|false,
           "ignoreAbove": <integer>,
           "similarity": { "type": "bm25|boolean|stableTfl" },
           "multi": { <string-field-definition> },
           "norms": "include|omit"
         }
       } 
     }
   }
   ```

   Click Create Search Index.

## View MongoDB Search Indexes

To view your MongoDB Search indexes on a collection using MongoDB Compass:

1. Connect to your cluster via MongoDB Compass.

   Open [Compass](https://www.mongodb.com/try/download/compass) and connect to your cluster. For detailed instructions, see [Connect to a Cluster via Compass.](https://www.mongodb.com/docs/atlas/compass-connection.md#std-label-atlas-connect-via-compass)

2. Specify the database and collection.

   On the Database screen, click the name of the database, then click the name of the collection.

3. Click the Indexes tab, then Search Indexes.

   The page displays the following:

   | Column Name | Description |
   | --- | --- |
   | Name and Fields | Name of the index and and the name of the indexed fields. |
   | Type | Type of index. Value can be `Search` or `Vector Search`. |
   | Status | Status of the index. To learn more, see [MongoDB Search Index Statuses.](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status) |
   | Actions | Actions you can perform on the index when you hover over the index. You can take the following actions: Aggregate - to switch to the Aggregations tab to run queries using the index.;  - to edit the index in raw JSON (Javascript Object Notation) format.;  - to delete the index. |

## Edit a MongoDB Search Index

To edit a MongoDB Search index using MongoDB Compass:

1. From the Indexes tab, click Search Indexes.

2. Hover over the index you want to edit.

3. Click the pencil icon to open the Edit dialog.

4. Make the changes and click Save.

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index using MongoDB Compass:

1. From the Indexes tab, click Search Indexes.

2. Hover over the index you want to delete.

3. Click the trash icon to open the confirmation dialog.

4. Type the name of the index you want to delete and click Save.

## Create a MongoDB Search Index

To use the [.NET/C# Driver](https://www.mongodb.com/docs/drivers/csharp/current/) to create a MongoDB Search index:

1. Construct a `BsonDocument` that defines the index.

2. Pass the `BsonDocument` to the `CreateOne()` or `CreateOneAsync()` method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the search indexes, call the `List()` method on a `SearchIndexes()` instance.

1. Create a new directory and initialize your project.

   Run the following command to create a new directory called `csharp-create-index`.

   ```sh
   mkdir csharp-create-index
   ```

   Run the following command to change to the new directory.

   ```sh
   cd csharp-create-index
   ```

   Run the following command to initialize your project.

   ```sh
   dotnet new console
   ```

2. Add the .NET/C# driver to your project as a dependency.

   Run the following command:

   ```sh
   dotnet add package MongoDB.Driver
   ```

3. Replace the contents of the `Program.cs` file with a `BsonDocument` that defines the index.

   ### Create One Search Index

   Replace the placeholder values in the following example application, which uses the `SearchIndexes.CreateOne` command to define a MongoDB Search index:

   | Value | Description |
   | --- | --- |
   | `<connection-string>` | Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver) |
   | `<databaseName>` | Database for which you want to create the index. |
   | `<collectionName>` | Collection for which you want to create the index. |
   | `<IndexName>` | The name of your index. If you omit the index name, MongoDB Search names the index `default`. |
   | `<IndexDefinition>` | The definition of your index. To learn about index definition syntax, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions) |

   ```csharp
   using MongoDB.Bson;
   using MongoDB.Driver;

   // connect to your Atlas deployment
   var uri = "<connection-string>";

   var client = new MongoClient(uri);

   var db = client.GetDatabase("<databaseName>");
   var collection = db.GetCollection<BsonDocument>("<collectionName>");

   // define your MongoDB Search index
   var index = new BsonDocument
   {
     { "mappings", new BsonDocument
       {
         { "dynamic", true }
       }
     }
   };

   var result = collection.SearchIndexes.CreateOne(index, "<indexName>");
   Console.WriteLine(result);

   ```

4. Compile and run the `Program.cs` file.

   Use the following command to run the project:

   ```shell
   dotnet run csharp-create-index.csproj
   ```

   **Output:**

   ```text
   default
   ```

**Tip: API Documentation**

To learn more about the methods on this page, see the [API documentation](https://mongodb.github.io/mongo-csharp-driver/2.21/apidocs/html/Methods_T_MongoDB_Driver_Search_IMongoSearchIndexManager.htm) for the .NET/C# driver.

## View MongoDB Search Indexes

To use the [.NET/C# Driver](https://www.mongodb.com/docs/drivers/csharp/current/) to retrieve your MongoDB Search indexes, use the `List()` or `ListAsync()` method.

### Example

The following sample application returns the indexes on a collection. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection that contains the search indexes that you want to retrieve.

**Note:**

The `List()` method returns a cursor instead of the indexes themselves. To access the indexes, use a cursor paradigm such as the `MoveNext()` method.

```csharp
using MongoDB.Bson;
using MongoDB.Driver;

// connect to your Atlas deployment
var uri = "<connection-string>";

var client = new MongoClient(uri);

var db = client.GetDatabase("<databaseName>");
var collection = db.GetCollection<BsonDocument>("<collectionName>");

// list your MongoDB Search indexes
var result = collection.SearchIndexes.List().ToList();
foreach (var index in result)
{
    Console.WriteLine(index);
}

```

To run the sample application, create a new .NET console project named `csharp-list-indexes` and copy the previous code example into the `Program.cs` file. Then, use the following command to run the project:

```shell
dotnet run csharp-list-indexes.csproj
```

**Output:**

```text
<indexes for this collection>
```

**Tip: API Documentation**

To learn more about the methods on this page, see the [API documentation](https://mongodb.github.io/mongo-csharp-driver/2.21/apidocs/html/Methods_T_MongoDB_Driver_Search_IMongoSearchIndexManager.htm) for the .NET/C# driver.

## Edit a MongoDB Search Index

To use the [.NET/C# Driver](https://www.mongodb.com/docs/drivers/csharp/current/) to edit a MongoDB Search index, use the `Update()` or `UpdateAsync()` method.

### Example

The following sample application updates an existing index definition. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection where you created the search index.

- The new index definition to replace the existing definition. In the example, you update an index to use [static mappings](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings). You can alter this definition to suit your specific indexing needs. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

- The name of the index that you want to update.

```csharp
using MongoDB.Bson;
using MongoDB.Driver;

// connect to your Atlas deployment
var uri = "<connection-string>";

var client = new MongoClient(uri);

var db = client.GetDatabase("<databaseName>");
var collection = db.GetCollection<BsonDocument>("<collectionName>");

// define your MongoDB Search index
var index = new BsonDocument
{
  // updated search index definition
  { "mappings", new BsonDocument
    {
      { "dynamic", false },
      { "fields", new BsonDocument
        {
          { "<field-name>", new BsonDocument
            {
              { "type", "<field-type>" }
            }
          }
        }
      }
    }
  }
};

collection.SearchIndexes.Update("<index-name>", index);

```

To run the sample application, create a new .NET console project named `csharp-update-index` and copy the previous code example into the `Program.cs` file. Then, use the following command to run the project:

```csharp
dotnet run csharp-update-index.csproj
```

**Note:**

The `Update()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

**Tip: API Documentation**

To learn more about the methods on this page, see the [API documentation](https://mongodb.github.io/mongo-csharp-driver/2.21/apidocs/html/Methods_T_MongoDB_Driver_Search_IMongoSearchIndexManager.htm) for the .NET/C# driver.

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To use the [.NET/C# Driver](https://www.mongodb.com/docs/drivers/csharp/current/) to delete a MongoDB Search index, use the `DropOne()` or `DropOneAsync()` method.

### Example

The following sample application deletes an index from a collection. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection that contains the search index that you want to delete.

- The name of the search index that you want to delete.

```csharp
using MongoDB.Bson;
using MongoDB.Driver;

// connect to your Atlas deployment
var uri = "<connection-string>";

var client = new MongoClient(uri);

var db = client.GetDatabase("<databaseName>");
var collection = db.GetCollection<BsonDocument>("<collectionName>");

// drop your MongoDB Search index
collection.SearchIndexes.DropOne("<index name>");

```

To run the sample application, create a new .NET console project named `csharp-delete-index` and copy the previous code example into the `Program.cs` file. Then, use the following command to run the project:

```csharp
dotnet run csharp-delete-index.csproj
```

**Note:**

The `DropOne()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

**Tip: API Documentation**

To learn more about the methods on this page, see the [API documentation](https://mongodb.github.io/mongo-csharp-driver/2.21/apidocs/html/Methods_T_MongoDB_Driver_Search_IMongoSearchIndexManager.htm) for the .NET/C# driver.

## Considerations for MongoDB Search Indexes

When creating and managing MongoDB Search indexes, consider the following:

### Index Consistency and Rebuilding

#### When is query data consistent after updates?

If you make changes to the collection for which you defined MongoDB Search indexes, the latest data might not be available immediately for queries. However, `mongot` monitors the change streams, which allows it to update stored copies of data, and MongoDB Search indexes are eventually consistent.

When you change an index definition, `mongot` automatically rebuilds the new index in the background, while continuing to serve queries with the old index to make sure there is no downtime. It is recommended that you wait for the index build to complete before running any queries using new index definitions. Using the new index during its build process can lead to unexpected results or incomplete data. This happens when you deploy `mongot` and `mongod` processes on the same node and when you deploy the processes on different nodes. Atlas also rebuilds indexes when you enable or disable [Encryption at Rest.](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption)

If you change the topology of your search deployment, MongoDB Search provisions and builds indexes on any new nodes before removing old nodes, to ensure there is no query downtime.

For deployments where both the `mongod` and `mongot` processes run on the same node, if MongoDB Search introduces changes that require rebuilding your indexes (such as some MongoDB Search features that require an [index update](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-index-rebuild)), Atlas automatically deploys additional nodes for free to build the indexes, while the old nodes continue to serve your queries.

WARNING: If you shard a collection that already has a MongoDB Search index, you might experience a brief period of incomplete search results while the index is building on a shard. Also, if you add a shard for an already sharded collection that contains a MongoDB Search index, your search queries against that collection might return incomplete results until the initial sync process completes on the added shards. To learn more, see [initial sync process.](https://www.mongodb.com/docs/search/performance/index-performance.md#std-label-troubleshoot-initial-sync)

IMPORTANT: If you use the [$out](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/) aggregation stage to modify a collection with an existing MongoDB Search index, you must delete and re-create the search index. If possible, consider using [$merge](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/) instead of `$out`.

### Dedicated Search Nodes

#### How are MongoDB Search indexes affected by dedicated Search Node architecture?

You can deploy [dedicated Search Nodes](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-what-is-search-node) to improve performance, scalability, and resource isolation.

If you've deployed Search Nodes, consider the following:

- Adding and adjusting [shards](https://www.mongodb.com/docs/manual/sharding.md#std-label-sharding-background) triggers a rebuild of the MongoDB Search index. During this index rebuild, the index might not have the most current data. Therefore, queries against data on those shards might fail or return incorrect results.

- If you [reshard](https://www.mongodb.com/docs/manual/core/sharding-reshard-a-collection.md#std-label-sharding-resharding) a collection with MongoDB Search indexes, MongoDB Search indexes on the collection become unavailable when the resharding operation completes. You *must* manually rebuild the MongoDB Search indexes once the operation completes.

- If you issue the command to [change the primary shard](https://www.mongodb.com/docs/manual/reference/command/movePrimary/) of a database, the MongoDB Search indexes for any unsharded collection under this database become unavailable once the operation completes. You *must* delete and create new MongoDB Search indexes once the [`movePrimary`](https://www.mongodb.com/docs/manual/reference/command/movePrimary.md#mongodb-dbcommand-dbcmd.movePrimary) operation is complete.

- Scaling your cluster by adding search nodes or by changing the search tier triggers a rebuild of the full MongoDB Search index. However, if your cluster has dedicated search nodes for which you haven't enabled [Encryption at Rest using Customer Key Management](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption), Atlas provides the following optimizations:

  - When you scale your search nodes, Atlas uses a recent copy of your index in S3 (Simple Storage Service), Google Cloud Storage, or Azure Blob Storage instead of rebuilding the entire MongoDB Search index on the new node.

  - For existing nodes, Atlas periodically takes and uploads a new incremental list of index files. Atlas retains index files for up to fourteen (14) days.

To learn more about MongoDB Search node architecture, see [MongoDB Search Deployment Options.](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-fts-deployment-options)

### Disk, Memory, and Resource Usage

#### How do MongoDB Search indexes affect your available disk space and memory?

Although the data stored on MongoDB Search isn't an identical copy of data from the collection on your Atlas cluster, MongoDB Search indexes still take some disk space and memory. If you enable the `store` option for fields that contain [string](https://www.mongodb.com/docs/search/indexes/field-types/string-type.md#std-label-bson-data-types-string) values or if you configure the [stored source fields](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition) in your index, MongoDB Search stores an identical copy of the specified fields on disk, which can take disk space.

**Important:**

If your collection contains documents that are 16MB (BSON (Binary Javascript Object Notation) limit), MongoDB Search fails to index the document, causes your index to become [STALE](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-index-statuses), and requires a full index rebuild. This issue can also occur when update operations on documents cause the change stream event to exceed the 16MB BSON (Binary Javascript Object Notation) limit. To minimize the risk of your index becoming stale, ensure that documents in your collection don't exceed 8MB. If your index has become stale, you must delete the large document(s) from your collection in order for the index rebuild to complete.

In addition:

- Structure your documents to minimize the size of sub-documents or arrays.

- Avoid operations that update or replace large fields, sub-documents, or arrays.

To learn more, see [Change Streams Production Recommendations](https://www.mongodb.com/docs/manual/administration/change-streams-production-recommendations/) and [Reduce the Size of Large Documents.](https://www.mongodb.com/docs/ops-manager/current/schema-advisor/reduce-document-size/)

### Concurrent Requests Error

#### What happens if there are too many concurrent MongoDB Search index management requests?

If there are too many concurrent index creation or other index management operation requests, MongoDB Search returns the following error:

```shell
Too many concurrent requests. Please try again later.
```

We recommend trying again after some time.

## Create a MongoDB Search Index

To use the [.NET/C# Driver](https://www.mongodb.com/docs/drivers/csharp/current/) to create a MongoDB Search index:

1. Construct a `BsonDocument` that defines the index.

2. Pass the `BsonDocument` to the `CreateOne()` or `CreateOneAsync()` method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the search indexes, call the `List()` method on a `SearchIndexes()` instance.

1. Create a new directory and initialize your project.

   Run the following command to create a new directory called `csharp-create-index`.

   ```sh
   mkdir csharp-create-index
   ```

   Run the following command to change to the new directory.

   ```sh
   cd csharp-create-index
   ```

   Run the following command to initialize your project.

   ```sh
   dotnet new console
   ```

2. Add the .NET/C# driver to your project as a dependency.

   Run the following command:

   ```sh
   dotnet add package MongoDB.Driver
   ```

3. Replace the contents of the `Program.cs` file with a `BsonDocument` that defines the index.

   ### Create One Search Index

   Replace the placeholder values in the following example application, which uses the `SearchIndexes.CreateOne` command to define a MongoDB Search index:

   | Value | Description |
   | --- | --- |
   | `<connection-string>` | Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver) |
   | `<databaseName>` | Database for which you want to create the index. |
   | `<collectionName>` | Collection for which you want to create the index. |
   | `<IndexName>` | The name of your index. If you omit the index name, MongoDB Search names the index `default`. |
   | `<IndexDefinition>` | The definition of your index. To learn about index definition syntax, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions) |

   ```csharp
   using MongoDB.Bson;
   using MongoDB.Driver;

   // connect to your Atlas deployment
   var uri = "<connection-string>";

   var client = new MongoClient(uri);

   var db = client.GetDatabase("<databaseName>");
   var collection = db.GetCollection<BsonDocument>("<collectionName>");

   // define your MongoDB Search index
   var index = new BsonDocument
   {
     { "mappings", new BsonDocument
       {
         { "dynamic", true }
       }
     }
   };

   var result = collection.SearchIndexes.CreateOne(index, "<indexName>");
   Console.WriteLine(result);

   ```

4. Compile and run the `Program.cs` file.

   Use the following command to run the project:

   ```shell
   dotnet run csharp-create-index.csproj
   ```

   **Output:**

   ```text
   default
   ```

**Tip: API Documentation**

To learn more about the methods on this page, see the [API documentation](https://mongodb.github.io/mongo-csharp-driver/2.21/apidocs/html/Methods_T_MongoDB_Driver_Search_IMongoSearchIndexManager.htm) for the .NET/C# driver.

## View MongoDB Search Indexes

To use the [.NET/C# Driver](https://www.mongodb.com/docs/drivers/csharp/current/) to retrieve your MongoDB Search indexes, use the `List()` or `ListAsync()` method.

### Example

The following sample application returns the indexes on a collection. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection that contains the search indexes that you want to retrieve.

**Note:**

The `List()` method returns a cursor instead of the indexes themselves. To access the indexes, use a cursor paradigm such as the `MoveNext()` method.

```csharp
using MongoDB.Bson;
using MongoDB.Driver;

// connect to your Atlas deployment
var uri = "<connection-string>";

var client = new MongoClient(uri);

var db = client.GetDatabase("<databaseName>");
var collection = db.GetCollection<BsonDocument>("<collectionName>");

// list your MongoDB Search indexes
var result = collection.SearchIndexes.List().ToList();
foreach (var index in result)
{
    Console.WriteLine(index);
}

```

To run the sample application, create a new .NET console project named `csharp-list-indexes` and copy the previous code example into the `Program.cs` file. Then, use the following command to run the project:

```shell
dotnet run csharp-list-indexes.csproj
```

**Output:**

```text
<indexes for this collection>
```

**Tip: API Documentation**

To learn more about the methods on this page, see the [API documentation](https://mongodb.github.io/mongo-csharp-driver/2.21/apidocs/html/Methods_T_MongoDB_Driver_Search_IMongoSearchIndexManager.htm) for the .NET/C# driver.

## Edit a MongoDB Search Index

To use the [.NET/C# Driver](https://www.mongodb.com/docs/drivers/csharp/current/) to edit a MongoDB Search index, use the `Update()` or `UpdateAsync()` method.

### Example

The following sample application updates an existing index definition. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection where you created the search index.

- The new index definition to replace the existing definition. In the example, you update an index to use [static mappings](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings). You can alter this definition to suit your specific indexing needs. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

- The name of the index that you want to update.

```csharp
using MongoDB.Bson;
using MongoDB.Driver;

// connect to your Atlas deployment
var uri = "<connection-string>";

var client = new MongoClient(uri);

var db = client.GetDatabase("<databaseName>");
var collection = db.GetCollection<BsonDocument>("<collectionName>");

// define your MongoDB Search index
var index = new BsonDocument
{
  // updated search index definition
  { "mappings", new BsonDocument
    {
      { "dynamic", false },
      { "fields", new BsonDocument
        {
          { "<field-name>", new BsonDocument
            {
              { "type", "<field-type>" }
            }
          }
        }
      }
    }
  }
};

collection.SearchIndexes.Update("<index-name>", index);

```

To run the sample application, create a new .NET console project named `csharp-update-index` and copy the previous code example into the `Program.cs` file. Then, use the following command to run the project:

```csharp
dotnet run csharp-update-index.csproj
```

**Note:**

The `Update()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

**Tip: API Documentation**

To learn more about the methods on this page, see the [API documentation](https://mongodb.github.io/mongo-csharp-driver/2.21/apidocs/html/Methods_T_MongoDB_Driver_Search_IMongoSearchIndexManager.htm) for the .NET/C# driver.

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To use the [.NET/C# Driver](https://www.mongodb.com/docs/drivers/csharp/current/) to delete a MongoDB Search index, use the `DropOne()` or `DropOneAsync()` method.

### Example

The following sample application deletes an index from a collection. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection that contains the search index that you want to delete.

- The name of the search index that you want to delete.

```csharp
using MongoDB.Bson;
using MongoDB.Driver;

// connect to your Atlas deployment
var uri = "<connection-string>";

var client = new MongoClient(uri);

var db = client.GetDatabase("<databaseName>");
var collection = db.GetCollection<BsonDocument>("<collectionName>");

// drop your MongoDB Search index
collection.SearchIndexes.DropOne("<index name>");

```

To run the sample application, create a new .NET console project named `csharp-delete-index` and copy the previous code example into the `Program.cs` file. Then, use the following command to run the project:

```csharp
dotnet run csharp-delete-index.csproj
```

**Note:**

The `DropOne()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

**Tip: API Documentation**

To learn more about the methods on this page, see the [API documentation](https://mongodb.github.io/mongo-csharp-driver/2.21/apidocs/html/Methods_T_MongoDB_Driver_Search_IMongoSearchIndexManager.htm) for the .NET/C# driver.

## Create a MongoDB Search Index

To use the [.NET/C# Driver](https://www.mongodb.com/docs/drivers/csharp/current/) to create a MongoDB Search index:

1. Construct a `BsonDocument` that defines the index.

2. Pass the `BsonDocument` to the `CreateOne()` or `CreateOneAsync()` method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the search indexes, call the `List()` method on a `SearchIndexes()` instance.

1. Create a new directory and initialize your project.

   Run the following command to create a new directory called `csharp-create-index`.

   ```sh
   mkdir csharp-create-index
   ```

   Run the following command to change to the new directory.

   ```sh
   cd csharp-create-index
   ```

   Run the following command to initialize your project.

   ```sh
   dotnet new console
   ```

2. Add the .NET/C# driver to your project as a dependency.

   Run the following command:

   ```sh
   dotnet add package MongoDB.Driver
   ```

3. Replace the contents of the `Program.cs` file with a `BsonDocument` that defines the index.

   ### Create One Search Index

   Replace the placeholder values in the following example application, which uses the `SearchIndexes.CreateOne` command to define a MongoDB Search index:

   | Value | Description |
   | --- | --- |
   | `<connection-string>` | Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver) |
   | `<databaseName>` | Database for which you want to create the index. |
   | `<collectionName>` | Collection for which you want to create the index. |
   | `<IndexName>` | The name of your index. If you omit the index name, MongoDB Search names the index `default`. |
   | `<IndexDefinition>` | The definition of your index. To learn about index definition syntax, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions) |

   ```csharp
   using MongoDB.Bson;
   using MongoDB.Driver;

   // connect to your Atlas deployment
   var uri = "<connection-string>";

   var client = new MongoClient(uri);

   var db = client.GetDatabase("<databaseName>");
   var collection = db.GetCollection<BsonDocument>("<collectionName>");

   // define your MongoDB Search index
   var index = new BsonDocument
   {
     { "mappings", new BsonDocument
       {
         { "dynamic", true }
       }
     }
   };

   var result = collection.SearchIndexes.CreateOne(index, "<indexName>");
   Console.WriteLine(result);

   ```

4. Compile and run the `Program.cs` file.

   Use the following command to run the project:

   ```shell
   dotnet run csharp-create-index.csproj
   ```

   **Output:**

   ```text
   default
   ```

**Tip: API Documentation**

To learn more about the methods on this page, see the [API documentation](https://mongodb.github.io/mongo-csharp-driver/2.21/apidocs/html/Methods_T_MongoDB_Driver_Search_IMongoSearchIndexManager.htm) for the .NET/C# driver.

## View MongoDB Search Indexes

To use the [.NET/C# Driver](https://www.mongodb.com/docs/drivers/csharp/current/) to retrieve your MongoDB Search indexes, use the `List()` or `ListAsync()` method.

### Example

The following sample application returns the indexes on a collection. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection that contains the search indexes that you want to retrieve.

**Note:**

The `List()` method returns a cursor instead of the indexes themselves. To access the indexes, use a cursor paradigm such as the `MoveNext()` method.

```csharp
using MongoDB.Bson;
using MongoDB.Driver;

// connect to your Atlas deployment
var uri = "<connection-string>";

var client = new MongoClient(uri);

var db = client.GetDatabase("<databaseName>");
var collection = db.GetCollection<BsonDocument>("<collectionName>");

// list your MongoDB Search indexes
var result = collection.SearchIndexes.List().ToList();
foreach (var index in result)
{
    Console.WriteLine(index);
}

```

To run the sample application, create a new .NET console project named `csharp-list-indexes` and copy the previous code example into the `Program.cs` file. Then, use the following command to run the project:

```shell
dotnet run csharp-list-indexes.csproj
```

**Output:**

```text
<indexes for this collection>
```

**Tip: API Documentation**

To learn more about the methods on this page, see the [API documentation](https://mongodb.github.io/mongo-csharp-driver/2.21/apidocs/html/Methods_T_MongoDB_Driver_Search_IMongoSearchIndexManager.htm) for the .NET/C# driver.

## Edit a MongoDB Search Index

To use the [.NET/C# Driver](https://www.mongodb.com/docs/drivers/csharp/current/) to edit a MongoDB Search index, use the `Update()` or `UpdateAsync()` method.

### Example

The following sample application updates an existing index definition. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection where you created the search index.

- The new index definition to replace the existing definition. In the example, you update an index to use [static mappings](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings). You can alter this definition to suit your specific indexing needs. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

- The name of the index that you want to update.

```csharp
using MongoDB.Bson;
using MongoDB.Driver;

// connect to your Atlas deployment
var uri = "<connection-string>";

var client = new MongoClient(uri);

var db = client.GetDatabase("<databaseName>");
var collection = db.GetCollection<BsonDocument>("<collectionName>");

// define your MongoDB Search index
var index = new BsonDocument
{
  // updated search index definition
  { "mappings", new BsonDocument
    {
      { "dynamic", false },
      { "fields", new BsonDocument
        {
          { "<field-name>", new BsonDocument
            {
              { "type", "<field-type>" }
            }
          }
        }
      }
    }
  }
};

collection.SearchIndexes.Update("<index-name>", index);

```

To run the sample application, create a new .NET console project named `csharp-update-index` and copy the previous code example into the `Program.cs` file. Then, use the following command to run the project:

```csharp
dotnet run csharp-update-index.csproj
```

**Note:**

The `Update()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

**Tip: API Documentation**

To learn more about the methods on this page, see the [API documentation](https://mongodb.github.io/mongo-csharp-driver/2.21/apidocs/html/Methods_T_MongoDB_Driver_Search_IMongoSearchIndexManager.htm) for the .NET/C# driver.

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To use the [.NET/C# Driver](https://www.mongodb.com/docs/drivers/csharp/current/) to delete a MongoDB Search index, use the `DropOne()` or `DropOneAsync()` method.

### Example

The following sample application deletes an index from a collection. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection that contains the search index that you want to delete.

- The name of the search index that you want to delete.

```csharp
using MongoDB.Bson;
using MongoDB.Driver;

// connect to your Atlas deployment
var uri = "<connection-string>";

var client = new MongoClient(uri);

var db = client.GetDatabase("<databaseName>");
var collection = db.GetCollection<BsonDocument>("<collectionName>");

// drop your MongoDB Search index
collection.SearchIndexes.DropOne("<index name>");

```

To run the sample application, create a new .NET console project named `csharp-delete-index` and copy the previous code example into the `Program.cs` file. Then, use the following command to run the project:

```csharp
dotnet run csharp-delete-index.csproj
```

**Note:**

The `DropOne()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

**Tip: API Documentation**

To learn more about the methods on this page, see the [API documentation](https://mongodb.github.io/mongo-csharp-driver/2.21/apidocs/html/Methods_T_MongoDB_Driver_Search_IMongoSearchIndexManager.htm) for the .NET/C# driver.

## Create a MongoDB Search Index

To use the [C Driver](https://www.mongodb.com/docs/drivers/c/) to create a MongoDB Search index, define the search index in your application and call the `mongoc_collection_command_simple()` method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the search indexes, run an aggregation operation with the `$listSearchIndexes` pipeline stage.

1. Create a new file named `create-index.c`.

2. Copy the following code example into the file.

   ### Create One Search Index

   The following sample application specifies the `createSearchIndexes` command to define a search index. Then, the application converts the command and search index information to BSON (Binary Javascript Object Notation) and passes this information to the `mongoc_collection_command_simple()` method to create the search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

   ```c
   #include <mongoc/mongoc.h>
   #include <stdlib.h>

   int main (void)
   {
       mongoc_client_t *client = NULL;
       mongoc_collection_t *collection = NULL;
       mongoc_database_t *database = NULL;
       bson_error_t error;
       bson_t cmd = BSON_INITIALIZER;
       bool ok = true;

       mongoc_init();

       // Connect to your Atlas deployment
       client = mongoc_client_new("<connectionString>");
       if (!client) {
           fprintf(stderr, "Failed to create a MongoDB client.\n");
           ok = false;
           goto cleanup;
       }

       // Access your database and collection
       database = mongoc_client_get_database(client, "<databaseName>");
       collection = mongoc_database_get_collection(database, "<collectionName>");

       // Specify the command and the new index
       const char *cmd_str = BSON_STR({
           "createSearchIndexes" : "<collectionName>",
           "indexes" : [ {
               "name" : "<indexName>",
               "definition" : {
                   "analyzer": "<indexAnalyzer>", 
                   "searchAnalyzer": "<queryAnalyzer>", 
                   "mappings": { 
                       "dynamic": <boolean>, 
                       "fields": { <fieldDefinition> } 
                   },
                   "numPartitions": <integer>,
                   "analyzers": [ <customAnalyzer> ],
                   "storedSource": <boolean> | {
                       <storedSourceDefinition>
                   },
                   "synonyms": [
                       {
                           <synonymMappingDefinition>
                       }
                   ] 
               }
   	    } ]
   	});

       // Convert your command to BSON
       if (!bson_init_from_json(&cmd, cmd_str, -1, &error)) {
           fprintf(stderr, "Failed to parse command: %s\n", error.message);
           ok = false;
           goto cleanup;
       }

       // Create the MongoDB Search index by running the command
       if (!mongoc_collection_command_simple (collection, &cmd, NULL, NULL, &error)) {
           fprintf(stderr, "Failed to run createSearchIndexes: %s\n", error.message);
           ok = false;
           goto cleanup;
       }
       printf ("Index created!\n");

   cleanup:
      mongoc_collection_destroy (collection);
      mongoc_client_destroy (client);
      mongoc_database_destroy (database);
      bson_destroy (&cmd);
      mongoc_cleanup ();
      return ok ? EXIT_SUCCESS : EXIT_FAILURE;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to create the index.

   - The name of your index. If you omit the index name, MongoDB Search names the index `default`.

   - The search index definition. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

4. Compile and run the file by using the following commands.

   ```shell
   gcc -o create-index create-index.c $(pkg-config --libs --cflags libmongoc-1.0)
   ./create-index
   ```

## View MongoDB Search Indexes

To use the [C Driver](https://www.mongodb.com/docs/drivers/c/) to retrieve your MongoDB Search indexes, use the `mongoc_collection_aggregate()` method to create an aggregation pipeline that includes the `$listSearchIndexes` stage.

### Example

1. Create a new file named `view-index.c`.

2. Copy the following code example into the file.

   The following sample application specifies the `$listSearchIndexes` stage in an aggregation pipeline. Then, the application passes the pipeline and the target collection to the `mongoc_collection_aggregate()` method. This method returns a cursor from which the code accesses and prints each MongoDB Search index:

   ```c
   #include <mongoc/mongoc.h>
   #include <stdlib.h>

   int main (void)
   {
       mongoc_client_t *client = NULL;
       mongoc_collection_t *collection = NULL;
       mongoc_database_t *database = NULL;
       bson_error_t error;
       bson_t cmd = BSON_INITIALIZER;
       bool ok = true;
       bson_t pipeline = BSON_INITIALIZER;
       mongoc_cursor_t *cursor = NULL;

       mongoc_init();

       // Connect to your Atlas deployment
       client = mongoc_client_new("<connectionString>");
       if (!client) {
           fprintf(stderr, "Failed to create a MongoDB client.\n");
           ok = false;
           goto cleanup;
       }

       // Access your database and collection
       database = mongoc_client_get_database(client, "<databaseName>");
       collection = mongoc_database_get_collection(database, "<collectionName>");

       // Create an aggregation pipeline with the $listSearchIndexes stage
       const char *pipeline_str =
           BSON_STR ({"pipeline" : [ {"$listSearchIndexes" : {}} ]});

       // Convert your aggregation pipeline to BSON
       if (!bson_init_from_json(&pipeline, pipeline_str, -1, &error)) {
           fprintf(stderr, "Failed to parse command: %s\n", error.message);
           ok = false;
           goto cleanup;
       }

       // Run the aggregation operation and iterate through the indexes returned
       cursor = mongoc_collection_aggregate (collection,
                                       MONGOC_QUERY_NONE,
                                       &pipeline,
                                       NULL,
                                       NULL);
       const bson_t *got;
       char *str;
       
       while (mongoc_cursor_next (cursor, &got)) {
         str = bson_as_canonical_extended_json (got, NULL);
         printf ("%s\n", str);
         bson_free (str);
      }

      if (mongoc_cursor_error (cursor, &error)) {
         fprintf (stderr, "Failed to iterate all documents: %s\n", error.message);
         ok = false;
         goto cleanup;
      }

   cleanup:
       mongoc_cursor_destroy(cursor);
       mongoc_collection_destroy(collection);
       mongoc_database_destroy(database);
       mongoc_client_destroy(client);
       bson_destroy(&pipeline);
       bson_destroy(&cmd);
      mongoc_cleanup ();
      return ok ? EXIT_SUCCESS : EXIT_FAILURE;
   }

   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to retrieve the indexes.

4. Compile and run the file by using the following commands.

   ```shell
   gcc -o view-index view-index.c $(pkg-config --libs --cflags libmongoc-1.0)
   ./view-index
   ```

## Edit a MongoDB Search Index

To use the [C Driver](https://www.mongodb.com/docs/drivers/c/) to edit your MongoDB Search indexes, specify the updated index information in your application and call the `mongoc_collection_command_simple()` method.

### Example

1. Create a new file named `edit-index.c`.

2. Copy the following code example into the file.

   The following sample application specifies the `updateSearchIndex` command, an updated index definition, and an existing index name. Then, the application converts the command and updated index information to BSON (Binary Javascript Object Notation) and passes this information to the `mongoc_collection_command_simple()` method to edit the search index.

   ```c
   #include <mongoc/mongoc.h>
   #include <stdlib.h>

   int main (void)
   {
       mongoc_client_t *client = NULL;
       mongoc_collection_t *collection = NULL;
       mongoc_database_t *database = NULL;
       bson_error_t error;
       bson_t cmd = BSON_INITIALIZER;
       bool ok = true;

       mongoc_init();

       // Connect to your Atlas deployment
       client = mongoc_client_new("<connectionString>");
       if (!client) {
           fprintf(stderr, "Failed to create a MongoDB client.\n");
           ok = false;
           goto cleanup;
       }

       // Access your database and collection
       database = mongoc_client_get_database(client, "<databaseName>");
       collection = mongoc_database_get_collection(database, "<collectionName>");

       // Specify the command and the updated index definition
       const char *cmd_str = BSON_STR({
           "updateSearchIndex" : "<collectionName>",
           "definition" : {"mappings" : {"dynamic" : true}},
           "name" : "<indexName>"
   	});

       // Convert your command to BSON
       if (!bson_init_from_json(&cmd, cmd_str, -1, &error)) {
           fprintf(stderr, "Failed to parse command: %s\n", error.message);
           ok = false;
           goto cleanup;
       }

       // Update the MongoDB search index by running the command
       if (!mongoc_collection_command_simple (collection, &cmd, NULL, NULL, &error)) {
           fprintf(stderr, "Failed to run updateSearchIndex: %s\n", error.message);
           ok = false;
           goto cleanup;
       }
       printf ("Index updated!\n");

   cleanup:
      mongoc_collection_destroy (collection);
      mongoc_database_destroy (database);
      mongoc_client_destroy (client);
      bson_destroy (&cmd);
      mongoc_cleanup ();
      return ok ? EXIT_SUCCESS : EXIT_FAILURE;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to update an index.

   - The name of the index that you want to update.

   - The fields to redefine your search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

4. Compile and run the file using the following commands.

   ```shell
   gcc -o edit-index edit-index.c $(pkg-config --libs --cflags libmongoc-1.0)
   ./edit-index
   ```

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To use the [C Driver](https://www.mongodb.com/docs/drivers/c/) to delete your MongoDB Search index, pass your collection and the drop command to the `mongoc_collection_command_simple()` method.

### Example

1. Create a new file named `delete-index.c`.

2. Copy the following code example into the file.

   The following sample application specifies the `dropSearchIndex` command and an existing index name. Then, the application converts the command and index information to BSON (Binary Javascript Object Notation) and passes this information to the `mongoc_collection_command_simple()` method to delete the search index.

   ```c
   #include <mongoc/mongoc.h>
   #include <stdlib.h>

   int main (void)
   {
       mongoc_client_t *client = NULL;
       mongoc_collection_t *collection = NULL;
       mongoc_database_t *database = NULL;
       bson_error_t error;
       bson_t cmd = BSON_INITIALIZER;
       bool ok = true;

       mongoc_init();

       // Connect to your Atlas deployment
       client = mongoc_client_new("<connectionString>");
       if (!client) {
           fprintf(stderr, "Failed to create a MongoDB client.\n");
           ok = false;
           goto cleanup;
       }

       // Access your database and collection
       database = mongoc_client_get_database(client, "<databaseName>");
       collection = mongoc_database_get_collection(database, "<collectionName>");

       // Specify the command and the index name
       const char *cmd_str =
           BSON_STR ({"dropSearchIndex" : "<collectionName>", "name" : "<indexName>"});

       // Convert your command to BSON
       if (!bson_init_from_json(&cmd, cmd_str, -1, &error)) {
           fprintf(stderr, "Failed to parse command: %s\n", error.message);
           ok = false;
           goto cleanup;
       }

       // Run the command to drop the search index
       if (!mongoc_collection_command_simple (collection, &cmd, NULL, NULL, &error)) {
           fprintf(stderr, "Failed to run dropSearchIndex: %s\n", error.message);
           ok = false;
           goto cleanup;
       }
       printf ("Index dropped!\n");

   cleanup:
       mongoc_collection_destroy(collection);
       mongoc_database_destroy(database);
       mongoc_client_destroy(client);
       bson_destroy(&cmd);
      mongoc_cleanup ();
      return ok ? EXIT_SUCCESS : EXIT_FAILURE;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to delete an index.

   - The name of the index that you want to delete.

4. Compile and run the file using the following commands.

   ```shell
   gcc -o delete-index delete-index.c $(pkg-config --libs --cflags libmongoc-1.0)
   ./delete-index
   ```

## Considerations for MongoDB Search Indexes

When creating and managing MongoDB Search indexes, consider the following:

### Index Consistency and Rebuilding

#### When is query data consistent after updates?

If you make changes to the collection for which you defined MongoDB Search indexes, the latest data might not be available immediately for queries. However, `mongot` monitors the change streams, which allows it to update stored copies of data, and MongoDB Search indexes are eventually consistent.

When you change an index definition, `mongot` automatically rebuilds the new index in the background, while continuing to serve queries with the old index to make sure there is no downtime. It is recommended that you wait for the index build to complete before running any queries using new index definitions. Using the new index during its build process can lead to unexpected results or incomplete data. This happens when you deploy `mongot` and `mongod` processes on the same node and when you deploy the processes on different nodes. Atlas also rebuilds indexes when you enable or disable [Encryption at Rest.](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption)

If you change the topology of your search deployment, MongoDB Search provisions and builds indexes on any new nodes before removing old nodes, to ensure there is no query downtime.

For deployments where both the `mongod` and `mongot` processes run on the same node, if MongoDB Search introduces changes that require rebuilding your indexes (such as some MongoDB Search features that require an [index update](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-index-rebuild)), Atlas automatically deploys additional nodes for free to build the indexes, while the old nodes continue to serve your queries.

WARNING: If you shard a collection that already has a MongoDB Search index, you might experience a brief period of incomplete search results while the index is building on a shard. Also, if you add a shard for an already sharded collection that contains a MongoDB Search index, your search queries against that collection might return incomplete results until the initial sync process completes on the added shards. To learn more, see [initial sync process.](https://www.mongodb.com/docs/search/performance/index-performance.md#std-label-troubleshoot-initial-sync)

IMPORTANT: If you use the [$out](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/) aggregation stage to modify a collection with an existing MongoDB Search index, you must delete and re-create the search index. If possible, consider using [$merge](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/) instead of `$out`.

### Dedicated Search Nodes

#### How are MongoDB Search indexes affected by dedicated Search Node architecture?

You can deploy [dedicated Search Nodes](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-what-is-search-node) to improve performance, scalability, and resource isolation.

If you've deployed Search Nodes, consider the following:

- Adding and adjusting [shards](https://www.mongodb.com/docs/manual/sharding.md#std-label-sharding-background) triggers a rebuild of the MongoDB Search index. During this index rebuild, the index might not have the most current data. Therefore, queries against data on those shards might fail or return incorrect results.

- If you [reshard](https://www.mongodb.com/docs/manual/core/sharding-reshard-a-collection.md#std-label-sharding-resharding) a collection with MongoDB Search indexes, MongoDB Search indexes on the collection become unavailable when the resharding operation completes. You *must* manually rebuild the MongoDB Search indexes once the operation completes.

- If you issue the command to [change the primary shard](https://www.mongodb.com/docs/manual/reference/command/movePrimary/) of a database, the MongoDB Search indexes for any unsharded collection under this database become unavailable once the operation completes. You *must* delete and create new MongoDB Search indexes once the [`movePrimary`](https://www.mongodb.com/docs/manual/reference/command/movePrimary.md#mongodb-dbcommand-dbcmd.movePrimary) operation is complete.

- Scaling your cluster by adding search nodes or by changing the search tier triggers a rebuild of the full MongoDB Search index. However, if your cluster has dedicated search nodes for which you haven't enabled [Encryption at Rest using Customer Key Management](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption), Atlas provides the following optimizations:

  - When you scale your search nodes, Atlas uses a recent copy of your index in S3 (Simple Storage Service), Google Cloud Storage, or Azure Blob Storage instead of rebuilding the entire MongoDB Search index on the new node.

  - For existing nodes, Atlas periodically takes and uploads a new incremental list of index files. Atlas retains index files for up to fourteen (14) days.

To learn more about MongoDB Search node architecture, see [MongoDB Search Deployment Options.](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-fts-deployment-options)

### Disk, Memory, and Resource Usage

#### How do MongoDB Search indexes affect your available disk space and memory?

Although the data stored on MongoDB Search isn't an identical copy of data from the collection on your Atlas cluster, MongoDB Search indexes still take some disk space and memory. If you enable the `store` option for fields that contain [string](https://www.mongodb.com/docs/search/indexes/field-types/string-type.md#std-label-bson-data-types-string) values or if you configure the [stored source fields](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition) in your index, MongoDB Search stores an identical copy of the specified fields on disk, which can take disk space.

**Important:**

If your collection contains documents that are 16MB (BSON (Binary Javascript Object Notation) limit), MongoDB Search fails to index the document, causes your index to become [STALE](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-index-statuses), and requires a full index rebuild. This issue can also occur when update operations on documents cause the change stream event to exceed the 16MB BSON (Binary Javascript Object Notation) limit. To minimize the risk of your index becoming stale, ensure that documents in your collection don't exceed 8MB. If your index has become stale, you must delete the large document(s) from your collection in order for the index rebuild to complete.

In addition:

- Structure your documents to minimize the size of sub-documents or arrays.

- Avoid operations that update or replace large fields, sub-documents, or arrays.

To learn more, see [Change Streams Production Recommendations](https://www.mongodb.com/docs/manual/administration/change-streams-production-recommendations/) and [Reduce the Size of Large Documents.](https://www.mongodb.com/docs/ops-manager/current/schema-advisor/reduce-document-size/)

### Concurrent Requests Error

#### What happens if there are too many concurrent MongoDB Search index management requests?

If there are too many concurrent index creation or other index management operation requests, MongoDB Search returns the following error:

```shell
Too many concurrent requests. Please try again later.
```

We recommend trying again after some time.

## Create a MongoDB Search Index

To use the [C Driver](https://www.mongodb.com/docs/drivers/c/) to create a MongoDB Search index, define the search index in your application and call the `mongoc_collection_command_simple()` method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the search indexes, run an aggregation operation with the `$listSearchIndexes` pipeline stage.

1. Create a new file named `create-index.c`.

2. Copy the following code example into the file.

   ### Create One Search Index

   The following sample application specifies the `createSearchIndexes` command to define a search index. Then, the application converts the command and search index information to BSON (Binary Javascript Object Notation) and passes this information to the `mongoc_collection_command_simple()` method to create the search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

   ```c
   #include <mongoc/mongoc.h>
   #include <stdlib.h>

   int main (void)
   {
       mongoc_client_t *client = NULL;
       mongoc_collection_t *collection = NULL;
       mongoc_database_t *database = NULL;
       bson_error_t error;
       bson_t cmd = BSON_INITIALIZER;
       bool ok = true;

       mongoc_init();

       // Connect to your Atlas deployment
       client = mongoc_client_new("<connectionString>");
       if (!client) {
           fprintf(stderr, "Failed to create a MongoDB client.\n");
           ok = false;
           goto cleanup;
       }

       // Access your database and collection
       database = mongoc_client_get_database(client, "<databaseName>");
       collection = mongoc_database_get_collection(database, "<collectionName>");

       // Specify the command and the new index
       const char *cmd_str = BSON_STR({
           "createSearchIndexes" : "<collectionName>",
           "indexes" : [ {
               "name" : "<indexName>",
               "definition" : {
                   "analyzer": "<indexAnalyzer>", 
                   "searchAnalyzer": "<queryAnalyzer>", 
                   "mappings": { 
                       "dynamic": <boolean>, 
                       "fields": { <fieldDefinition> } 
                   },
                   "numPartitions": <integer>,
                   "analyzers": [ <customAnalyzer> ],
                   "storedSource": <boolean> | {
                       <storedSourceDefinition>
                   },
                   "synonyms": [
                       {
                           <synonymMappingDefinition>
                       }
                   ] 
               }
   	    } ]
   	});

       // Convert your command to BSON
       if (!bson_init_from_json(&cmd, cmd_str, -1, &error)) {
           fprintf(stderr, "Failed to parse command: %s\n", error.message);
           ok = false;
           goto cleanup;
       }

       // Create the MongoDB Search index by running the command
       if (!mongoc_collection_command_simple (collection, &cmd, NULL, NULL, &error)) {
           fprintf(stderr, "Failed to run createSearchIndexes: %s\n", error.message);
           ok = false;
           goto cleanup;
       }
       printf ("Index created!\n");

   cleanup:
      mongoc_collection_destroy (collection);
      mongoc_client_destroy (client);
      mongoc_database_destroy (database);
      bson_destroy (&cmd);
      mongoc_cleanup ();
      return ok ? EXIT_SUCCESS : EXIT_FAILURE;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to create the index.

   - The name of your index. If you omit the index name, MongoDB Search names the index `default`.

   - The search index definition. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

4. Compile and run the file by using the following commands.

   ```shell
   gcc -o create-index create-index.c $(pkg-config --libs --cflags libmongoc-1.0)
   ./create-index
   ```

## View MongoDB Search Indexes

To use the [C Driver](https://www.mongodb.com/docs/drivers/c/) to retrieve your MongoDB Search indexes, use the `mongoc_collection_aggregate()` method to create an aggregation pipeline that includes the `$listSearchIndexes` stage.

### Example

1. Create a new file named `view-index.c`.

2. Copy the following code example into the file.

   The following sample application specifies the `$listSearchIndexes` stage in an aggregation pipeline. Then, the application passes the pipeline and the target collection to the `mongoc_collection_aggregate()` method. This method returns a cursor from which the code accesses and prints each MongoDB Search index:

   ```c
   #include <mongoc/mongoc.h>
   #include <stdlib.h>

   int main (void)
   {
       mongoc_client_t *client = NULL;
       mongoc_collection_t *collection = NULL;
       mongoc_database_t *database = NULL;
       bson_error_t error;
       bson_t cmd = BSON_INITIALIZER;
       bool ok = true;
       bson_t pipeline = BSON_INITIALIZER;
       mongoc_cursor_t *cursor = NULL;

       mongoc_init();

       // Connect to your Atlas deployment
       client = mongoc_client_new("<connectionString>");
       if (!client) {
           fprintf(stderr, "Failed to create a MongoDB client.\n");
           ok = false;
           goto cleanup;
       }

       // Access your database and collection
       database = mongoc_client_get_database(client, "<databaseName>");
       collection = mongoc_database_get_collection(database, "<collectionName>");

       // Create an aggregation pipeline with the $listSearchIndexes stage
       const char *pipeline_str =
           BSON_STR ({"pipeline" : [ {"$listSearchIndexes" : {}} ]});

       // Convert your aggregation pipeline to BSON
       if (!bson_init_from_json(&pipeline, pipeline_str, -1, &error)) {
           fprintf(stderr, "Failed to parse command: %s\n", error.message);
           ok = false;
           goto cleanup;
       }

       // Run the aggregation operation and iterate through the indexes returned
       cursor = mongoc_collection_aggregate (collection,
                                       MONGOC_QUERY_NONE,
                                       &pipeline,
                                       NULL,
                                       NULL);
       const bson_t *got;
       char *str;
       
       while (mongoc_cursor_next (cursor, &got)) {
         str = bson_as_canonical_extended_json (got, NULL);
         printf ("%s\n", str);
         bson_free (str);
      }

      if (mongoc_cursor_error (cursor, &error)) {
         fprintf (stderr, "Failed to iterate all documents: %s\n", error.message);
         ok = false;
         goto cleanup;
      }

   cleanup:
       mongoc_cursor_destroy(cursor);
       mongoc_collection_destroy(collection);
       mongoc_database_destroy(database);
       mongoc_client_destroy(client);
       bson_destroy(&pipeline);
       bson_destroy(&cmd);
      mongoc_cleanup ();
      return ok ? EXIT_SUCCESS : EXIT_FAILURE;
   }

   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to retrieve the indexes.

4. Compile and run the file by using the following commands.

   ```shell
   gcc -o view-index view-index.c $(pkg-config --libs --cflags libmongoc-1.0)
   ./view-index
   ```

## Edit a MongoDB Search Index

To use the [C Driver](https://www.mongodb.com/docs/drivers/c/) to edit your MongoDB Search indexes, specify the updated index information in your application and call the `mongoc_collection_command_simple()` method.

### Example

1. Create a new file named `edit-index.c`.

2. Copy the following code example into the file.

   The following sample application specifies the `updateSearchIndex` command, an updated index definition, and an existing index name. Then, the application converts the command and updated index information to BSON (Binary Javascript Object Notation) and passes this information to the `mongoc_collection_command_simple()` method to edit the search index.

   ```c
   #include <mongoc/mongoc.h>
   #include <stdlib.h>

   int main (void)
   {
       mongoc_client_t *client = NULL;
       mongoc_collection_t *collection = NULL;
       mongoc_database_t *database = NULL;
       bson_error_t error;
       bson_t cmd = BSON_INITIALIZER;
       bool ok = true;

       mongoc_init();

       // Connect to your Atlas deployment
       client = mongoc_client_new("<connectionString>");
       if (!client) {
           fprintf(stderr, "Failed to create a MongoDB client.\n");
           ok = false;
           goto cleanup;
       }

       // Access your database and collection
       database = mongoc_client_get_database(client, "<databaseName>");
       collection = mongoc_database_get_collection(database, "<collectionName>");

       // Specify the command and the updated index definition
       const char *cmd_str = BSON_STR({
           "updateSearchIndex" : "<collectionName>",
           "definition" : {"mappings" : {"dynamic" : true}},
           "name" : "<indexName>"
   	});

       // Convert your command to BSON
       if (!bson_init_from_json(&cmd, cmd_str, -1, &error)) {
           fprintf(stderr, "Failed to parse command: %s\n", error.message);
           ok = false;
           goto cleanup;
       }

       // Update the MongoDB search index by running the command
       if (!mongoc_collection_command_simple (collection, &cmd, NULL, NULL, &error)) {
           fprintf(stderr, "Failed to run updateSearchIndex: %s\n", error.message);
           ok = false;
           goto cleanup;
       }
       printf ("Index updated!\n");

   cleanup:
      mongoc_collection_destroy (collection);
      mongoc_database_destroy (database);
      mongoc_client_destroy (client);
      bson_destroy (&cmd);
      mongoc_cleanup ();
      return ok ? EXIT_SUCCESS : EXIT_FAILURE;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to update an index.

   - The name of the index that you want to update.

   - The fields to redefine your search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

4. Compile and run the file using the following commands.

   ```shell
   gcc -o edit-index edit-index.c $(pkg-config --libs --cflags libmongoc-1.0)
   ./edit-index
   ```

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To use the [C Driver](https://www.mongodb.com/docs/drivers/c/) to delete your MongoDB Search index, pass your collection and the drop command to the `mongoc_collection_command_simple()` method.

### Example

1. Create a new file named `delete-index.c`.

2. Copy the following code example into the file.

   The following sample application specifies the `dropSearchIndex` command and an existing index name. Then, the application converts the command and index information to BSON (Binary Javascript Object Notation) and passes this information to the `mongoc_collection_command_simple()` method to delete the search index.

   ```c
   #include <mongoc/mongoc.h>
   #include <stdlib.h>

   int main (void)
   {
       mongoc_client_t *client = NULL;
       mongoc_collection_t *collection = NULL;
       mongoc_database_t *database = NULL;
       bson_error_t error;
       bson_t cmd = BSON_INITIALIZER;
       bool ok = true;

       mongoc_init();

       // Connect to your Atlas deployment
       client = mongoc_client_new("<connectionString>");
       if (!client) {
           fprintf(stderr, "Failed to create a MongoDB client.\n");
           ok = false;
           goto cleanup;
       }

       // Access your database and collection
       database = mongoc_client_get_database(client, "<databaseName>");
       collection = mongoc_database_get_collection(database, "<collectionName>");

       // Specify the command and the index name
       const char *cmd_str =
           BSON_STR ({"dropSearchIndex" : "<collectionName>", "name" : "<indexName>"});

       // Convert your command to BSON
       if (!bson_init_from_json(&cmd, cmd_str, -1, &error)) {
           fprintf(stderr, "Failed to parse command: %s\n", error.message);
           ok = false;
           goto cleanup;
       }

       // Run the command to drop the search index
       if (!mongoc_collection_command_simple (collection, &cmd, NULL, NULL, &error)) {
           fprintf(stderr, "Failed to run dropSearchIndex: %s\n", error.message);
           ok = false;
           goto cleanup;
       }
       printf ("Index dropped!\n");

   cleanup:
       mongoc_collection_destroy(collection);
       mongoc_database_destroy(database);
       mongoc_client_destroy(client);
       bson_destroy(&cmd);
      mongoc_cleanup ();
      return ok ? EXIT_SUCCESS : EXIT_FAILURE;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to delete an index.

   - The name of the index that you want to delete.

4. Compile and run the file using the following commands.

   ```shell
   gcc -o delete-index delete-index.c $(pkg-config --libs --cflags libmongoc-1.0)
   ./delete-index
   ```

## Create a MongoDB Search Index

To use the [C Driver](https://www.mongodb.com/docs/drivers/c/) to create a MongoDB Search index, define the search index in your application and call the `mongoc_collection_command_simple()` method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the search indexes, run an aggregation operation with the `$listSearchIndexes` pipeline stage.

1. Create a new file named `create-index.c`.

2. Copy the following code example into the file.

   ### Create One Search Index

   The following sample application specifies the `createSearchIndexes` command to define a search index. Then, the application converts the command and search index information to BSON (Binary Javascript Object Notation) and passes this information to the `mongoc_collection_command_simple()` method to create the search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

   ```c
   #include <mongoc/mongoc.h>
   #include <stdlib.h>

   int main (void)
   {
       mongoc_client_t *client = NULL;
       mongoc_collection_t *collection = NULL;
       mongoc_database_t *database = NULL;
       bson_error_t error;
       bson_t cmd = BSON_INITIALIZER;
       bool ok = true;

       mongoc_init();

       // Connect to your Atlas deployment
       client = mongoc_client_new("<connectionString>");
       if (!client) {
           fprintf(stderr, "Failed to create a MongoDB client.\n");
           ok = false;
           goto cleanup;
       }

       // Access your database and collection
       database = mongoc_client_get_database(client, "<databaseName>");
       collection = mongoc_database_get_collection(database, "<collectionName>");

       // Specify the command and the new index
       const char *cmd_str = BSON_STR({
           "createSearchIndexes" : "<collectionName>",
           "indexes" : [ {
               "name" : "<indexName>",
               "definition" : {
                   "analyzer": "<indexAnalyzer>", 
                   "searchAnalyzer": "<queryAnalyzer>", 
                   "mappings": { 
                       "dynamic": <boolean>, 
                       "fields": { <fieldDefinition> } 
                   },
                   "numPartitions": <integer>,
                   "analyzers": [ <customAnalyzer> ],
                   "storedSource": <boolean> | {
                       <storedSourceDefinition>
                   },
                   "synonyms": [
                       {
                           <synonymMappingDefinition>
                       }
                   ] 
               }
   	    } ]
   	});

       // Convert your command to BSON
       if (!bson_init_from_json(&cmd, cmd_str, -1, &error)) {
           fprintf(stderr, "Failed to parse command: %s\n", error.message);
           ok = false;
           goto cleanup;
       }

       // Create the MongoDB Search index by running the command
       if (!mongoc_collection_command_simple (collection, &cmd, NULL, NULL, &error)) {
           fprintf(stderr, "Failed to run createSearchIndexes: %s\n", error.message);
           ok = false;
           goto cleanup;
       }
       printf ("Index created!\n");

   cleanup:
      mongoc_collection_destroy (collection);
      mongoc_client_destroy (client);
      mongoc_database_destroy (database);
      bson_destroy (&cmd);
      mongoc_cleanup ();
      return ok ? EXIT_SUCCESS : EXIT_FAILURE;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to create the index.

   - The name of your index. If you omit the index name, MongoDB Search names the index `default`.

   - The search index definition. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

4. Compile and run the file by using the following commands.

   ```shell
   gcc -o create-index create-index.c $(pkg-config --libs --cflags libmongoc-1.0)
   ./create-index
   ```

## View MongoDB Search Indexes

To use the [C Driver](https://www.mongodb.com/docs/drivers/c/) to retrieve your MongoDB Search indexes, use the `mongoc_collection_aggregate()` method to create an aggregation pipeline that includes the `$listSearchIndexes` stage.

### Example

1. Create a new file named `view-index.c`.

2. Copy the following code example into the file.

   The following sample application specifies the `$listSearchIndexes` stage in an aggregation pipeline. Then, the application passes the pipeline and the target collection to the `mongoc_collection_aggregate()` method. This method returns a cursor from which the code accesses and prints each MongoDB Search index:

   ```c
   #include <mongoc/mongoc.h>
   #include <stdlib.h>

   int main (void)
   {
       mongoc_client_t *client = NULL;
       mongoc_collection_t *collection = NULL;
       mongoc_database_t *database = NULL;
       bson_error_t error;
       bson_t cmd = BSON_INITIALIZER;
       bool ok = true;
       bson_t pipeline = BSON_INITIALIZER;
       mongoc_cursor_t *cursor = NULL;

       mongoc_init();

       // Connect to your Atlas deployment
       client = mongoc_client_new("<connectionString>");
       if (!client) {
           fprintf(stderr, "Failed to create a MongoDB client.\n");
           ok = false;
           goto cleanup;
       }

       // Access your database and collection
       database = mongoc_client_get_database(client, "<databaseName>");
       collection = mongoc_database_get_collection(database, "<collectionName>");

       // Create an aggregation pipeline with the $listSearchIndexes stage
       const char *pipeline_str =
           BSON_STR ({"pipeline" : [ {"$listSearchIndexes" : {}} ]});

       // Convert your aggregation pipeline to BSON
       if (!bson_init_from_json(&pipeline, pipeline_str, -1, &error)) {
           fprintf(stderr, "Failed to parse command: %s\n", error.message);
           ok = false;
           goto cleanup;
       }

       // Run the aggregation operation and iterate through the indexes returned
       cursor = mongoc_collection_aggregate (collection,
                                       MONGOC_QUERY_NONE,
                                       &pipeline,
                                       NULL,
                                       NULL);
       const bson_t *got;
       char *str;
       
       while (mongoc_cursor_next (cursor, &got)) {
         str = bson_as_canonical_extended_json (got, NULL);
         printf ("%s\n", str);
         bson_free (str);
      }

      if (mongoc_cursor_error (cursor, &error)) {
         fprintf (stderr, "Failed to iterate all documents: %s\n", error.message);
         ok = false;
         goto cleanup;
      }

   cleanup:
       mongoc_cursor_destroy(cursor);
       mongoc_collection_destroy(collection);
       mongoc_database_destroy(database);
       mongoc_client_destroy(client);
       bson_destroy(&pipeline);
       bson_destroy(&cmd);
      mongoc_cleanup ();
      return ok ? EXIT_SUCCESS : EXIT_FAILURE;
   }

   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to retrieve the indexes.

4. Compile and run the file by using the following commands.

   ```shell
   gcc -o view-index view-index.c $(pkg-config --libs --cflags libmongoc-1.0)
   ./view-index
   ```

## Edit a MongoDB Search Index

To use the [C Driver](https://www.mongodb.com/docs/drivers/c/) to edit your MongoDB Search indexes, specify the updated index information in your application and call the `mongoc_collection_command_simple()` method.

### Example

1. Create a new file named `edit-index.c`.

2. Copy the following code example into the file.

   The following sample application specifies the `updateSearchIndex` command, an updated index definition, and an existing index name. Then, the application converts the command and updated index information to BSON (Binary Javascript Object Notation) and passes this information to the `mongoc_collection_command_simple()` method to edit the search index.

   ```c
   #include <mongoc/mongoc.h>
   #include <stdlib.h>

   int main (void)
   {
       mongoc_client_t *client = NULL;
       mongoc_collection_t *collection = NULL;
       mongoc_database_t *database = NULL;
       bson_error_t error;
       bson_t cmd = BSON_INITIALIZER;
       bool ok = true;

       mongoc_init();

       // Connect to your Atlas deployment
       client = mongoc_client_new("<connectionString>");
       if (!client) {
           fprintf(stderr, "Failed to create a MongoDB client.\n");
           ok = false;
           goto cleanup;
       }

       // Access your database and collection
       database = mongoc_client_get_database(client, "<databaseName>");
       collection = mongoc_database_get_collection(database, "<collectionName>");

       // Specify the command and the updated index definition
       const char *cmd_str = BSON_STR({
           "updateSearchIndex" : "<collectionName>",
           "definition" : {"mappings" : {"dynamic" : true}},
           "name" : "<indexName>"
   	});

       // Convert your command to BSON
       if (!bson_init_from_json(&cmd, cmd_str, -1, &error)) {
           fprintf(stderr, "Failed to parse command: %s\n", error.message);
           ok = false;
           goto cleanup;
       }

       // Update the MongoDB search index by running the command
       if (!mongoc_collection_command_simple (collection, &cmd, NULL, NULL, &error)) {
           fprintf(stderr, "Failed to run updateSearchIndex: %s\n", error.message);
           ok = false;
           goto cleanup;
       }
       printf ("Index updated!\n");

   cleanup:
      mongoc_collection_destroy (collection);
      mongoc_database_destroy (database);
      mongoc_client_destroy (client);
      bson_destroy (&cmd);
      mongoc_cleanup ();
      return ok ? EXIT_SUCCESS : EXIT_FAILURE;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to update an index.

   - The name of the index that you want to update.

   - The fields to redefine your search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

4. Compile and run the file using the following commands.

   ```shell
   gcc -o edit-index edit-index.c $(pkg-config --libs --cflags libmongoc-1.0)
   ./edit-index
   ```

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To use the [C Driver](https://www.mongodb.com/docs/drivers/c/) to delete your MongoDB Search index, pass your collection and the drop command to the `mongoc_collection_command_simple()` method.

### Example

1. Create a new file named `delete-index.c`.

2. Copy the following code example into the file.

   The following sample application specifies the `dropSearchIndex` command and an existing index name. Then, the application converts the command and index information to BSON (Binary Javascript Object Notation) and passes this information to the `mongoc_collection_command_simple()` method to delete the search index.

   ```c
   #include <mongoc/mongoc.h>
   #include <stdlib.h>

   int main (void)
   {
       mongoc_client_t *client = NULL;
       mongoc_collection_t *collection = NULL;
       mongoc_database_t *database = NULL;
       bson_error_t error;
       bson_t cmd = BSON_INITIALIZER;
       bool ok = true;

       mongoc_init();

       // Connect to your Atlas deployment
       client = mongoc_client_new("<connectionString>");
       if (!client) {
           fprintf(stderr, "Failed to create a MongoDB client.\n");
           ok = false;
           goto cleanup;
       }

       // Access your database and collection
       database = mongoc_client_get_database(client, "<databaseName>");
       collection = mongoc_database_get_collection(database, "<collectionName>");

       // Specify the command and the index name
       const char *cmd_str =
           BSON_STR ({"dropSearchIndex" : "<collectionName>", "name" : "<indexName>"});

       // Convert your command to BSON
       if (!bson_init_from_json(&cmd, cmd_str, -1, &error)) {
           fprintf(stderr, "Failed to parse command: %s\n", error.message);
           ok = false;
           goto cleanup;
       }

       // Run the command to drop the search index
       if (!mongoc_collection_command_simple (collection, &cmd, NULL, NULL, &error)) {
           fprintf(stderr, "Failed to run dropSearchIndex: %s\n", error.message);
           ok = false;
           goto cleanup;
       }
       printf ("Index dropped!\n");

   cleanup:
       mongoc_collection_destroy(collection);
       mongoc_database_destroy(database);
       mongoc_client_destroy(client);
       bson_destroy(&cmd);
      mongoc_cleanup ();
      return ok ? EXIT_SUCCESS : EXIT_FAILURE;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to delete an index.

   - The name of the index that you want to delete.

4. Compile and run the file using the following commands.

   ```shell
   gcc -o delete-index delete-index.c $(pkg-config --libs --cflags libmongoc-1.0)
   ./delete-index
   ```

## Create a MongoDB Search Index

To use the [C++ Driver](https://www.mongodb.com/docs/drivers/cxx/) to create a MongoDB Search index, define the search index in your application and call the `create_one()` or `create_many()` method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the search indexes, call the `list()` method on a search index view instance.

1. Create a new file named `create-index.cpp`.

2. Copy the following code example into the file.

   ### Create One Search Index

   The following sample application passes a search index name and definition to the `search_index_model()` method to dynamically index the fields in your collection. Then, the application passes the search index specifications to the `create_one()` method to create the search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

   ```cpp
   #include <bsoncxx/builder/basic/document.hpp>
   #include <bsoncxx/builder/basic/kvp.hpp>
   #include <mongocxx/client.hpp>
   #include <mongocxx/instance.hpp>
   #include <mongocxx/search_index_view.hpp>

   using bsoncxx::builder::basic::kvp;
   using bsoncxx::builder::basic::make_document;
   using namespace mongocxx;

   int main()
   { 
       try
       {
           // Connect to your Atlas deployment
           mongocxx::instance instance{};
           mongocxx::uri uri("<connectionString>");
           mongocxx::client client(uri); 

           // Access your database and collection
           auto db = client["<databaseName>"];
           auto collection = db["<collectionName>"];

           // Create an index model with your index name and definition
           auto siv = collection.search_indexes();
           auto name = "<indexName>";
           auto definition = make_document(kvp("mappings", make_document(kvp("dynamic", true))));
           auto model = search_index_model(name, definition.view());

           // Create the search index
           siv.create_one(model);
           std::cout << "Index created!" << std::endl;
       }
       catch (const std::exception& e) 
       {
           std::cout<< "Exception: " << e.what() << std::endl;
       }

       return 0;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to create the index.

   - The name of your index. If you omit the index name, MongoDB Search names the index `default`.

   ### Create One Search Index

4. Compile and run the file by using the following commands.

   ```shell
   g++ -o create-index create-index.cpp $(pkg-config --cflags --libs libmongocxx)
   ./create-index
   ```

## View MongoDB Search Indexes

To use the [C++ Driver](https://www.mongodb.com/docs/drivers/cxx/) to retrieve your MongoDB Search indexes, call the `list()` method on a search index view.

### Example

1. Create a new file named `view-index.cpp`.

2. Copy the following code example into the file.

   The following sample application uses the `search_indexes()` method on the target collection to instantiate a search index view. Then, the application calls the `list()` method on the view. This method returns a cursor from which the code accesses and prints each MongoDB Search index.

   ```cpp
   #include <bsoncxx/json.hpp>
   #include <mongocxx/client.hpp>
   #include <mongocxx/instance.hpp>
   #include <mongocxx/search_index_view.hpp>

   using namespace mongocxx;

   int main()
   { 
       mongocxx::instance instance{};
       try
       {
           // Connect to your Atlas deployment
           mongocxx::uri uri("<connectionString>");
           mongocxx::client client(uri); 

           // Access your database and collection
           auto db = client["<databaseName>"];
           auto collection = db["<collectionName>"];

           // Access and print the indexes in your collection
           auto siv = collection.search_indexes();
           auto cursor = siv.list();

           for (auto&& doc : cursor) {
               std::cout << bsoncxx::to_json(doc) << std::endl;
           };
       }
       catch (const std::exception& e) 
       {
           std::cout<< "Exception: " << e.what() << std::endl;
       }

       return 0;
   }

   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to retrieve the indexes.

4. Compile and run the file using the following commands.

   ```shell
   g++ -o view-index view-index.cpp $(pkg-config --cflags --libs libmongocxx)
   ./view-index
   ```

## Edit a MongoDB Search Index

To use the [C++ Driver](https://www.mongodb.com/docs/drivers/cxx/) to edit a MongoDB Search index, call the `update_one()` method on a search index view.

### Example

1. Create a new file named `edit-index.cpp`.

2. Copy the following code example into the file.

   The following sample application instantiates a search index view and specifies a new MongoDB Search index definition. Then, the application passes this definition and an existing index name to the `update_one()` method, which updates the existing index to reflect the new definition document.

   ```cpp
   #include <bsoncxx/builder/basic/document.hpp>
   #include <mongocxx/client.hpp>
   #include <mongocxx/instance.hpp>
   #include <mongocxx/search_index_view.hpp>

   using namespace mongocxx;
   using bsoncxx::builder::basic::make_document;

   int main()
   { 
       mongocxx::instance instance{};
       try
       {
           // Connect to your Atlas deployment
           mongocxx::uri uri("<connectionString>");
           mongocxx::client client(uri); 

           // Access your database and collection
           auto db = client["<databaseName>"];
           auto collection = db["<collectionName>"];

           // Access the indexes in your collection
           auto siv = collection.search_indexes();

           // Specify a new definiton and update your search index
           auto newDefinition = make_document(kvp("mappings", make_document(kvp("dynamic", true))));
           siv.update_one("<indexName>", newDefinition.view());
           
       }
       catch (const std::exception& e) 
       {
           std::cout<< "Exception: " << e.what() << std::endl;
       }

       return 0;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to update an index.

   - The name of the index that you want to update.

   - The fields to redefine your search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

4. Compile and run the file using the following commands.

   ```shell
   g++ -o edit-index edit-index.cpp $(pkg-config --cflags --libs libmongocxx)
   ./edit-index
   ```

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To use the [C++ Driver](https://www.mongodb.com/docs/drivers/cxx/) to delete your MongoDB Search index, call the `drop_one()` method on a search index view.

### Example

1. Create a new file named `delete-index.cpp`.

2. Copy the following code example into the file.

   The following sample application uses the `search_indexes()` method on the target collection to instantiate a search index view. Then, the application calls the `drop_one()` method on the view and passes a MongoDB Search index name as a parameter to delete the index.

   ```cpp
   #include <mongocxx/client.hpp>
   #include <mongocxx/instance.hpp>
   #include <mongocxx/search_index_view.hpp>

   using namespace mongocxx;

   int main()
   { 
       mongocxx::instance instance{};
       try
       {
           // Connect to your Atlas deployment
           mongocxx::uri uri("<connectionString>");
           mongocxx::client client(uri); 

           // Access your database and collection
           auto db = client["<databaseName>"];
           auto collection = db["<collectionName>"];

           // Access the indexes in your collection
           auto siv = collection.search_indexes();

           // Delete your search index
           auto name = "<indexName>";
           siv.drop_one(name);
           
       }
       catch (const std::exception& e) 
       {
           std::cout<< "Exception: " << e.what() << std::endl;
       }

       return 0;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to retrieve the indexes.

   - The name of the index that you want to delete.

4. Compile and run the file using the following commands.

   ```shell
   g++ -o delete-index delete-index.cpp $(pkg-config --cflags --libs libmongocxx)
   ./delete-index
   ```

## Considerations for MongoDB Search Indexes

When creating and managing MongoDB Search indexes, consider the following:

### Index Consistency and Rebuilding

#### When is query data consistent after updates?

If you make changes to the collection for which you defined MongoDB Search indexes, the latest data might not be available immediately for queries. However, `mongot` monitors the change streams, which allows it to update stored copies of data, and MongoDB Search indexes are eventually consistent.

When you change an index definition, `mongot` automatically rebuilds the new index in the background, while continuing to serve queries with the old index to make sure there is no downtime. It is recommended that you wait for the index build to complete before running any queries using new index definitions. Using the new index during its build process can lead to unexpected results or incomplete data. This happens when you deploy `mongot` and `mongod` processes on the same node and when you deploy the processes on different nodes. Atlas also rebuilds indexes when you enable or disable [Encryption at Rest.](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption)

If you change the topology of your search deployment, MongoDB Search provisions and builds indexes on any new nodes before removing old nodes, to ensure there is no query downtime.

For deployments where both the `mongod` and `mongot` processes run on the same node, if MongoDB Search introduces changes that require rebuilding your indexes (such as some MongoDB Search features that require an [index update](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-index-rebuild)), Atlas automatically deploys additional nodes for free to build the indexes, while the old nodes continue to serve your queries.

WARNING: If you shard a collection that already has a MongoDB Search index, you might experience a brief period of incomplete search results while the index is building on a shard. Also, if you add a shard for an already sharded collection that contains a MongoDB Search index, your search queries against that collection might return incomplete results until the initial sync process completes on the added shards. To learn more, see [initial sync process.](https://www.mongodb.com/docs/search/performance/index-performance.md#std-label-troubleshoot-initial-sync)

IMPORTANT: If you use the [$out](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/) aggregation stage to modify a collection with an existing MongoDB Search index, you must delete and re-create the search index. If possible, consider using [$merge](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/) instead of `$out`.

### Dedicated Search Nodes

#### How are MongoDB Search indexes affected by dedicated Search Node architecture?

You can deploy [dedicated Search Nodes](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-what-is-search-node) to improve performance, scalability, and resource isolation.

If you've deployed Search Nodes, consider the following:

- Adding and adjusting [shards](https://www.mongodb.com/docs/manual/sharding.md#std-label-sharding-background) triggers a rebuild of the MongoDB Search index. During this index rebuild, the index might not have the most current data. Therefore, queries against data on those shards might fail or return incorrect results.

- If you [reshard](https://www.mongodb.com/docs/manual/core/sharding-reshard-a-collection.md#std-label-sharding-resharding) a collection with MongoDB Search indexes, MongoDB Search indexes on the collection become unavailable when the resharding operation completes. You *must* manually rebuild the MongoDB Search indexes once the operation completes.

- If you issue the command to [change the primary shard](https://www.mongodb.com/docs/manual/reference/command/movePrimary/) of a database, the MongoDB Search indexes for any unsharded collection under this database become unavailable once the operation completes. You *must* delete and create new MongoDB Search indexes once the [`movePrimary`](https://www.mongodb.com/docs/manual/reference/command/movePrimary.md#mongodb-dbcommand-dbcmd.movePrimary) operation is complete.

- Scaling your cluster by adding search nodes or by changing the search tier triggers a rebuild of the full MongoDB Search index. However, if your cluster has dedicated search nodes for which you haven't enabled [Encryption at Rest using Customer Key Management](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption), Atlas provides the following optimizations:

  - When you scale your search nodes, Atlas uses a recent copy of your index in S3 (Simple Storage Service), Google Cloud Storage, or Azure Blob Storage instead of rebuilding the entire MongoDB Search index on the new node.

  - For existing nodes, Atlas periodically takes and uploads a new incremental list of index files. Atlas retains index files for up to fourteen (14) days.

To learn more about MongoDB Search node architecture, see [MongoDB Search Deployment Options.](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-fts-deployment-options)

### Disk, Memory, and Resource Usage

#### How do MongoDB Search indexes affect your available disk space and memory?

Although the data stored on MongoDB Search isn't an identical copy of data from the collection on your Atlas cluster, MongoDB Search indexes still take some disk space and memory. If you enable the `store` option for fields that contain [string](https://www.mongodb.com/docs/search/indexes/field-types/string-type.md#std-label-bson-data-types-string) values or if you configure the [stored source fields](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition) in your index, MongoDB Search stores an identical copy of the specified fields on disk, which can take disk space.

**Important:**

If your collection contains documents that are 16MB (BSON (Binary Javascript Object Notation) limit), MongoDB Search fails to index the document, causes your index to become [STALE](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-index-statuses), and requires a full index rebuild. This issue can also occur when update operations on documents cause the change stream event to exceed the 16MB BSON (Binary Javascript Object Notation) limit. To minimize the risk of your index becoming stale, ensure that documents in your collection don't exceed 8MB. If your index has become stale, you must delete the large document(s) from your collection in order for the index rebuild to complete.

In addition:

- Structure your documents to minimize the size of sub-documents or arrays.

- Avoid operations that update or replace large fields, sub-documents, or arrays.

To learn more, see [Change Streams Production Recommendations](https://www.mongodb.com/docs/manual/administration/change-streams-production-recommendations/) and [Reduce the Size of Large Documents.](https://www.mongodb.com/docs/ops-manager/current/schema-advisor/reduce-document-size/)

### Concurrent Requests Error

#### What happens if there are too many concurrent MongoDB Search index management requests?

If there are too many concurrent index creation or other index management operation requests, MongoDB Search returns the following error:

```shell
Too many concurrent requests. Please try again later.
```

We recommend trying again after some time.

## Create a MongoDB Search Index

To use the [C++ Driver](https://www.mongodb.com/docs/drivers/cxx/) to create a MongoDB Search index, define the search index in your application and call the `create_one()` or `create_many()` method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the search indexes, call the `list()` method on a search index view instance.

1. Create a new file named `create-index.cpp`.

2. Copy the following code example into the file.

   ### Create One Search Index

   The following sample application passes a search index name and definition to the `search_index_model()` method to dynamically index the fields in your collection. Then, the application passes the search index specifications to the `create_one()` method to create the search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

   ```cpp
   #include <bsoncxx/builder/basic/document.hpp>
   #include <bsoncxx/builder/basic/kvp.hpp>
   #include <mongocxx/client.hpp>
   #include <mongocxx/instance.hpp>
   #include <mongocxx/search_index_view.hpp>

   using bsoncxx::builder::basic::kvp;
   using bsoncxx::builder::basic::make_document;
   using namespace mongocxx;

   int main()
   { 
       try
       {
           // Connect to your Atlas deployment
           mongocxx::instance instance{};
           mongocxx::uri uri("<connectionString>");
           mongocxx::client client(uri); 

           // Access your database and collection
           auto db = client["<databaseName>"];
           auto collection = db["<collectionName>"];

           // Create an index model with your index name and definition
           auto siv = collection.search_indexes();
           auto name = "<indexName>";
           auto definition = make_document(kvp("mappings", make_document(kvp("dynamic", true))));
           auto model = search_index_model(name, definition.view());

           // Create the search index
           siv.create_one(model);
           std::cout << "Index created!" << std::endl;
       }
       catch (const std::exception& e) 
       {
           std::cout<< "Exception: " << e.what() << std::endl;
       }

       return 0;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to create the index.

   - The name of your index. If you omit the index name, MongoDB Search names the index `default`.

   ### Create One Search Index

4. Compile and run the file by using the following commands.

   ```shell
   g++ -o create-index create-index.cpp $(pkg-config --cflags --libs libmongocxx)
   ./create-index
   ```

## View MongoDB Search Indexes

To use the [C++ Driver](https://www.mongodb.com/docs/drivers/cxx/) to retrieve your MongoDB Search indexes, call the `list()` method on a search index view.

### Example

1. Create a new file named `view-index.cpp`.

2. Copy the following code example into the file.

   The following sample application uses the `search_indexes()` method on the target collection to instantiate a search index view. Then, the application calls the `list()` method on the view. This method returns a cursor from which the code accesses and prints each MongoDB Search index.

   ```cpp
   #include <bsoncxx/json.hpp>
   #include <mongocxx/client.hpp>
   #include <mongocxx/instance.hpp>
   #include <mongocxx/search_index_view.hpp>

   using namespace mongocxx;

   int main()
   { 
       mongocxx::instance instance{};
       try
       {
           // Connect to your Atlas deployment
           mongocxx::uri uri("<connectionString>");
           mongocxx::client client(uri); 

           // Access your database and collection
           auto db = client["<databaseName>"];
           auto collection = db["<collectionName>"];

           // Access and print the indexes in your collection
           auto siv = collection.search_indexes();
           auto cursor = siv.list();

           for (auto&& doc : cursor) {
               std::cout << bsoncxx::to_json(doc) << std::endl;
           };
       }
       catch (const std::exception& e) 
       {
           std::cout<< "Exception: " << e.what() << std::endl;
       }

       return 0;
   }

   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to retrieve the indexes.

4. Compile and run the file using the following commands.

   ```shell
   g++ -o view-index view-index.cpp $(pkg-config --cflags --libs libmongocxx)
   ./view-index
   ```

## Edit a MongoDB Search Index

To use the [C++ Driver](https://www.mongodb.com/docs/drivers/cxx/) to edit a MongoDB Search index, call the `update_one()` method on a search index view.

### Example

1. Create a new file named `edit-index.cpp`.

2. Copy the following code example into the file.

   The following sample application instantiates a search index view and specifies a new MongoDB Search index definition. Then, the application passes this definition and an existing index name to the `update_one()` method, which updates the existing index to reflect the new definition document.

   ```cpp
   #include <bsoncxx/builder/basic/document.hpp>
   #include <mongocxx/client.hpp>
   #include <mongocxx/instance.hpp>
   #include <mongocxx/search_index_view.hpp>

   using namespace mongocxx;
   using bsoncxx::builder::basic::make_document;

   int main()
   { 
       mongocxx::instance instance{};
       try
       {
           // Connect to your Atlas deployment
           mongocxx::uri uri("<connectionString>");
           mongocxx::client client(uri); 

           // Access your database and collection
           auto db = client["<databaseName>"];
           auto collection = db["<collectionName>"];

           // Access the indexes in your collection
           auto siv = collection.search_indexes();

           // Specify a new definiton and update your search index
           auto newDefinition = make_document(kvp("mappings", make_document(kvp("dynamic", true))));
           siv.update_one("<indexName>", newDefinition.view());
           
       }
       catch (const std::exception& e) 
       {
           std::cout<< "Exception: " << e.what() << std::endl;
       }

       return 0;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to update an index.

   - The name of the index that you want to update.

   - The fields to redefine your search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

4. Compile and run the file using the following commands.

   ```shell
   g++ -o edit-index edit-index.cpp $(pkg-config --cflags --libs libmongocxx)
   ./edit-index
   ```

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To use the [C++ Driver](https://www.mongodb.com/docs/drivers/cxx/) to delete your MongoDB Search index, call the `drop_one()` method on a search index view.

### Example

1. Create a new file named `delete-index.cpp`.

2. Copy the following code example into the file.

   The following sample application uses the `search_indexes()` method on the target collection to instantiate a search index view. Then, the application calls the `drop_one()` method on the view and passes a MongoDB Search index name as a parameter to delete the index.

   ```cpp
   #include <mongocxx/client.hpp>
   #include <mongocxx/instance.hpp>
   #include <mongocxx/search_index_view.hpp>

   using namespace mongocxx;

   int main()
   { 
       mongocxx::instance instance{};
       try
       {
           // Connect to your Atlas deployment
           mongocxx::uri uri("<connectionString>");
           mongocxx::client client(uri); 

           // Access your database and collection
           auto db = client["<databaseName>"];
           auto collection = db["<collectionName>"];

           // Access the indexes in your collection
           auto siv = collection.search_indexes();

           // Delete your search index
           auto name = "<indexName>";
           siv.drop_one(name);
           
       }
       catch (const std::exception& e) 
       {
           std::cout<< "Exception: " << e.what() << std::endl;
       }

       return 0;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to retrieve the indexes.

   - The name of the index that you want to delete.

4. Compile and run the file using the following commands.

   ```shell
   g++ -o delete-index delete-index.cpp $(pkg-config --cflags --libs libmongocxx)
   ./delete-index
   ```

## Create a MongoDB Search Index

To use the [C++ Driver](https://www.mongodb.com/docs/drivers/cxx/) to create a MongoDB Search index, define the search index in your application and call the `create_one()` or `create_many()` method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the search indexes, call the `list()` method on a search index view instance.

1. Create a new file named `create-index.cpp`.

2. Copy the following code example into the file.

   ### Create One Search Index

   The following sample application passes a search index name and definition to the `search_index_model()` method to dynamically index the fields in your collection. Then, the application passes the search index specifications to the `create_one()` method to create the search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

   ```cpp
   #include <bsoncxx/builder/basic/document.hpp>
   #include <bsoncxx/builder/basic/kvp.hpp>
   #include <mongocxx/client.hpp>
   #include <mongocxx/instance.hpp>
   #include <mongocxx/search_index_view.hpp>

   using bsoncxx::builder::basic::kvp;
   using bsoncxx::builder::basic::make_document;
   using namespace mongocxx;

   int main()
   { 
       try
       {
           // Connect to your Atlas deployment
           mongocxx::instance instance{};
           mongocxx::uri uri("<connectionString>");
           mongocxx::client client(uri); 

           // Access your database and collection
           auto db = client["<databaseName>"];
           auto collection = db["<collectionName>"];

           // Create an index model with your index name and definition
           auto siv = collection.search_indexes();
           auto name = "<indexName>";
           auto definition = make_document(kvp("mappings", make_document(kvp("dynamic", true))));
           auto model = search_index_model(name, definition.view());

           // Create the search index
           siv.create_one(model);
           std::cout << "Index created!" << std::endl;
       }
       catch (const std::exception& e) 
       {
           std::cout<< "Exception: " << e.what() << std::endl;
       }

       return 0;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to create the index.

   - The name of your index. If you omit the index name, MongoDB Search names the index `default`.

   ### Create One Search Index

4. Compile and run the file by using the following commands.

   ```shell
   g++ -o create-index create-index.cpp $(pkg-config --cflags --libs libmongocxx)
   ./create-index
   ```

## View MongoDB Search Indexes

To use the [C++ Driver](https://www.mongodb.com/docs/drivers/cxx/) to retrieve your MongoDB Search indexes, call the `list()` method on a search index view.

### Example

1. Create a new file named `view-index.cpp`.

2. Copy the following code example into the file.

   The following sample application uses the `search_indexes()` method on the target collection to instantiate a search index view. Then, the application calls the `list()` method on the view. This method returns a cursor from which the code accesses and prints each MongoDB Search index.

   ```cpp
   #include <bsoncxx/json.hpp>
   #include <mongocxx/client.hpp>
   #include <mongocxx/instance.hpp>
   #include <mongocxx/search_index_view.hpp>

   using namespace mongocxx;

   int main()
   { 
       mongocxx::instance instance{};
       try
       {
           // Connect to your Atlas deployment
           mongocxx::uri uri("<connectionString>");
           mongocxx::client client(uri); 

           // Access your database and collection
           auto db = client["<databaseName>"];
           auto collection = db["<collectionName>"];

           // Access and print the indexes in your collection
           auto siv = collection.search_indexes();
           auto cursor = siv.list();

           for (auto&& doc : cursor) {
               std::cout << bsoncxx::to_json(doc) << std::endl;
           };
       }
       catch (const std::exception& e) 
       {
           std::cout<< "Exception: " << e.what() << std::endl;
       }

       return 0;
   }

   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to retrieve the indexes.

4. Compile and run the file using the following commands.

   ```shell
   g++ -o view-index view-index.cpp $(pkg-config --cflags --libs libmongocxx)
   ./view-index
   ```

## Edit a MongoDB Search Index

To use the [C++ Driver](https://www.mongodb.com/docs/drivers/cxx/) to edit a MongoDB Search index, call the `update_one()` method on a search index view.

### Example

1. Create a new file named `edit-index.cpp`.

2. Copy the following code example into the file.

   The following sample application instantiates a search index view and specifies a new MongoDB Search index definition. Then, the application passes this definition and an existing index name to the `update_one()` method, which updates the existing index to reflect the new definition document.

   ```cpp
   #include <bsoncxx/builder/basic/document.hpp>
   #include <mongocxx/client.hpp>
   #include <mongocxx/instance.hpp>
   #include <mongocxx/search_index_view.hpp>

   using namespace mongocxx;
   using bsoncxx::builder::basic::make_document;

   int main()
   { 
       mongocxx::instance instance{};
       try
       {
           // Connect to your Atlas deployment
           mongocxx::uri uri("<connectionString>");
           mongocxx::client client(uri); 

           // Access your database and collection
           auto db = client["<databaseName>"];
           auto collection = db["<collectionName>"];

           // Access the indexes in your collection
           auto siv = collection.search_indexes();

           // Specify a new definiton and update your search index
           auto newDefinition = make_document(kvp("mappings", make_document(kvp("dynamic", true))));
           siv.update_one("<indexName>", newDefinition.view());
           
       }
       catch (const std::exception& e) 
       {
           std::cout<< "Exception: " << e.what() << std::endl;
       }

       return 0;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to update an index.

   - The name of the index that you want to update.

   - The fields to redefine your search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

4. Compile and run the file using the following commands.

   ```shell
   g++ -o edit-index edit-index.cpp $(pkg-config --cflags --libs libmongocxx)
   ./edit-index
   ```

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To use the [C++ Driver](https://www.mongodb.com/docs/drivers/cxx/) to delete your MongoDB Search index, call the `drop_one()` method on a search index view.

### Example

1. Create a new file named `delete-index.cpp`.

2. Copy the following code example into the file.

   The following sample application uses the `search_indexes()` method on the target collection to instantiate a search index view. Then, the application calls the `drop_one()` method on the view and passes a MongoDB Search index name as a parameter to delete the index.

   ```cpp
   #include <mongocxx/client.hpp>
   #include <mongocxx/instance.hpp>
   #include <mongocxx/search_index_view.hpp>

   using namespace mongocxx;

   int main()
   { 
       mongocxx::instance instance{};
       try
       {
           // Connect to your Atlas deployment
           mongocxx::uri uri("<connectionString>");
           mongocxx::client client(uri); 

           // Access your database and collection
           auto db = client["<databaseName>"];
           auto collection = db["<collectionName>"];

           // Access the indexes in your collection
           auto siv = collection.search_indexes();

           // Delete your search index
           auto name = "<indexName>";
           siv.drop_one(name);
           
       }
       catch (const std::exception& e) 
       {
           std::cout<< "Exception: " << e.what() << std::endl;
       }

       return 0;
   }
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to retrieve the indexes.

   - The name of the index that you want to delete.

4. Compile and run the file using the following commands.

   ```shell
   g++ -o delete-index delete-index.cpp $(pkg-config --cflags --libs libmongocxx)
   ./delete-index
   ```

## Create a MongoDB Search Index

To create a MongoDB Search index through the [Node Driver:](https://www.mongodb.com/docs/drivers/node/current/)

1. Define the search index from your application.

2. Run the `createSearchIndex` or `createSearchIndexes` helper method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the indexes, call the `listSearchIndexes()` method on your collection.

1. Create a file named `create-index.js`.

2. Define the search index.

   ### Create One Search Index

   Replace the placeholder values in the following example application named `create-index.js`, which uses the `createSearchIndex` command to define a MongoDB Search index:

   | Value | Description |
   | --- | --- |
   | `<connectionString>` | Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver) |
   | `<databaseName>` | Database for which you want to create the index. |
   | `<collectionName>` | Collection for which you want to create the index. |
   | `<indexName>` | Name of your index. If you omit the index name, MongoDB Search names the index `default`. |
   | `<IndexDefinition>` | The definition of your index. To learn about index definition syntax, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions) |

   ```javascript
   import { MongoClient } from "mongodb";

   // connect to your Atlas deployment
   const uri =  "<connectionString>";

   const client = new MongoClient(uri);

   async function run() {
     try {
       const database = client.db("<databaseName>");
       const collection = database.collection("<collectionName>");
       
       // define your MongoDB Search index
       const index = {
           name: "<indexName>",
           definition: {
               /* search index definition fields */
               <indexDefinition>
           }
       }

       // run the helper method
       const result = await collection.createSearchIndex(index);
       console.log(result);
     } finally {
       await client.close();
     }
   }
   run().catch(console.dir);

   ```

3. Run the sample application to create the index.

   Use the following command:

   ```shell
   node create-index.js
   ```

   **Output:**

   ```text
   <index-name>
   ```

## View MongoDB Search Indexes

To retrieve your MongoDB Search indexes through the [Node Driver](https://www.mongodb.com/docs/drivers/node/current/), use the `listSearchIndexes` helper method.

### Example

You can use the following sample application named `list-indexes.js` to return the indexes on your collection. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection that contains the search indexes that you want to retrieve.

- The index name if you want to retrieve a specific index. To return all indexes on the collection, omit this value.

**Note:**

The `listSearchIndexes` command returns a cursor. As a result, it doesn't immediately return the indexes matched by the command. To access the results, use a cursor paradigm such as the `toArray()` method. To learn more, see [Access Data From a Cursor.](https://www.mongodb.com/docs/drivers/node/current/fundamentals/crud/read-operations/cursor/)

```javascript
import { MongoClient } from "mongodb";

// connect to your Atlas deployment
const uri =  "<connection-string>";

const client = new MongoClient(uri);

async function run() {
  try {
    const database = client.db("<databaseName>");
    const collection = database.collection("<collectionName>");

    // run the helper method
    const result = await collection.listSearchIndexes("<index-name>").toArray();
    console.log(result);
  } finally {
    await client.close();
  }
}
run().catch(console.dir);

```

To run the sample application, use the following command. Your results should resemble the example output:

```shell
node list-indexes.js
```

**Output:**

```json
[
   {
      id: '648b4ad4d697b73bf9d2e5e0',
      name: 'default',
      status: 'READY',
      queryable: true,
      latestDefinition: { mappings: { dynamic: true } }
   },
   {
      id: '648b4ad4d697b73bf9d2e5e1',
      name: 'example-index',
      status: 'PENDING',
      queryable: false,
      latestDefinition: {
         mappings: { dynamic: false, fields: { text: { type: 'string' } } }
      }
   }
]
```

## Edit a MongoDB Search Index

To edit a MongoDB Search index through the [Node Driver](https://www.mongodb.com/docs/drivers/node/current/), use the `updateSearchIndex` helper method.

### Example

You can use the following sample application named `update-index.js` to update an existing index definition. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection where you created the search index.

- The new index definition to replace the existing definition. In the example, you update an index to use [static mappings](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings). You can alter this definition to suit your specific indexing needs. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

- The name of the index that you want to update.

```javascript
import { MongoClient } from "mongodb";

// connect to your Atlas deployment
const uri =  "<connection-string>";

const client = new MongoClient(uri);

async function run() {
  try {
    const database = client.db("<databaseName>");
    const collection = database.collection("<collectionName>");

    // define your MongoDB Search index
    const index = {
        /* updated search index definition */
        "mappings": {
            "dynamic": false,
            "fields": {
              "<field-name>": {
                "type": "<field-type>"
              }
            }
        }
    }

    // run the helper method
    await collection.updateSearchIndex("<index-name>", index);
  } finally {
    await client.close();
  }
}
run().catch(console.dir);

```

To run the sample application, use the following command:

```text
node update-index.js
```

**Note:**

The `updateSearchIndex()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index through the [Node Driver](https://www.mongodb.com/docs/drivers/node/current/), use the `dropSearchIndex` helper method.

### Example

You can use the following sample application named `drop-index.js` to delete an index on your collection. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection where you created the search index.

- The name of the index that you want to delete.

```javascript
// connect to your Atlas deployment
const uri = "<connection-string>";

const client = new MongoClient(uri);

async function run() {
  try {
    const database = client.db("<databaseName>");
    const collection = database.collection("<collectionName>");

    // run the helper method
    await collection.dropSearchIndex("<index-name>");
    
  } finally {
    await client.close();
  }
}
run().catch(console.dir);

```

To run the sample application, use the following command.

```text
node drop-index.js
```

**Note:**

The `dropSearchIndex()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

## Considerations for MongoDB Search Indexes

When creating and managing MongoDB Search indexes, consider the following:

### Index Consistency and Rebuilding

#### When is query data consistent after updates?

If you make changes to the collection for which you defined MongoDB Search indexes, the latest data might not be available immediately for queries. However, `mongot` monitors the change streams, which allows it to update stored copies of data, and MongoDB Search indexes are eventually consistent.

When you change an index definition, `mongot` automatically rebuilds the new index in the background, while continuing to serve queries with the old index to make sure there is no downtime. It is recommended that you wait for the index build to complete before running any queries using new index definitions. Using the new index during its build process can lead to unexpected results or incomplete data. This happens when you deploy `mongot` and `mongod` processes on the same node and when you deploy the processes on different nodes. Atlas also rebuilds indexes when you enable or disable [Encryption at Rest.](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption)

If you change the topology of your search deployment, MongoDB Search provisions and builds indexes on any new nodes before removing old nodes, to ensure there is no query downtime.

For deployments where both the `mongod` and `mongot` processes run on the same node, if MongoDB Search introduces changes that require rebuilding your indexes (such as some MongoDB Search features that require an [index update](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-index-rebuild)), Atlas automatically deploys additional nodes for free to build the indexes, while the old nodes continue to serve your queries.

WARNING: If you shard a collection that already has a MongoDB Search index, you might experience a brief period of incomplete search results while the index is building on a shard. Also, if you add a shard for an already sharded collection that contains a MongoDB Search index, your search queries against that collection might return incomplete results until the initial sync process completes on the added shards. To learn more, see [initial sync process.](https://www.mongodb.com/docs/search/performance/index-performance.md#std-label-troubleshoot-initial-sync)

IMPORTANT: If you use the [$out](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/) aggregation stage to modify a collection with an existing MongoDB Search index, you must delete and re-create the search index. If possible, consider using [$merge](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/) instead of `$out`.

### Dedicated Search Nodes

#### How are MongoDB Search indexes affected by dedicated Search Node architecture?

You can deploy [dedicated Search Nodes](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-what-is-search-node) to improve performance, scalability, and resource isolation.

If you've deployed Search Nodes, consider the following:

- Adding and adjusting [shards](https://www.mongodb.com/docs/manual/sharding.md#std-label-sharding-background) triggers a rebuild of the MongoDB Search index. During this index rebuild, the index might not have the most current data. Therefore, queries against data on those shards might fail or return incorrect results.

- If you [reshard](https://www.mongodb.com/docs/manual/core/sharding-reshard-a-collection.md#std-label-sharding-resharding) a collection with MongoDB Search indexes, MongoDB Search indexes on the collection become unavailable when the resharding operation completes. You *must* manually rebuild the MongoDB Search indexes once the operation completes.

- If you issue the command to [change the primary shard](https://www.mongodb.com/docs/manual/reference/command/movePrimary/) of a database, the MongoDB Search indexes for any unsharded collection under this database become unavailable once the operation completes. You *must* delete and create new MongoDB Search indexes once the [`movePrimary`](https://www.mongodb.com/docs/manual/reference/command/movePrimary.md#mongodb-dbcommand-dbcmd.movePrimary) operation is complete.

- Scaling your cluster by adding search nodes or by changing the search tier triggers a rebuild of the full MongoDB Search index. However, if your cluster has dedicated search nodes for which you haven't enabled [Encryption at Rest using Customer Key Management](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption), Atlas provides the following optimizations:

  - When you scale your search nodes, Atlas uses a recent copy of your index in S3 (Simple Storage Service), Google Cloud Storage, or Azure Blob Storage instead of rebuilding the entire MongoDB Search index on the new node.

  - For existing nodes, Atlas periodically takes and uploads a new incremental list of index files. Atlas retains index files for up to fourteen (14) days.

To learn more about MongoDB Search node architecture, see [MongoDB Search Deployment Options.](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-fts-deployment-options)

### Disk, Memory, and Resource Usage

#### How do MongoDB Search indexes affect your available disk space and memory?

Although the data stored on MongoDB Search isn't an identical copy of data from the collection on your Atlas cluster, MongoDB Search indexes still take some disk space and memory. If you enable the `store` option for fields that contain [string](https://www.mongodb.com/docs/search/indexes/field-types/string-type.md#std-label-bson-data-types-string) values or if you configure the [stored source fields](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition) in your index, MongoDB Search stores an identical copy of the specified fields on disk, which can take disk space.

**Important:**

If your collection contains documents that are 16MB (BSON (Binary Javascript Object Notation) limit), MongoDB Search fails to index the document, causes your index to become [STALE](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-index-statuses), and requires a full index rebuild. This issue can also occur when update operations on documents cause the change stream event to exceed the 16MB BSON (Binary Javascript Object Notation) limit. To minimize the risk of your index becoming stale, ensure that documents in your collection don't exceed 8MB. If your index has become stale, you must delete the large document(s) from your collection in order for the index rebuild to complete.

In addition:

- Structure your documents to minimize the size of sub-documents or arrays.

- Avoid operations that update or replace large fields, sub-documents, or arrays.

To learn more, see [Change Streams Production Recommendations](https://www.mongodb.com/docs/manual/administration/change-streams-production-recommendations/) and [Reduce the Size of Large Documents.](https://www.mongodb.com/docs/ops-manager/current/schema-advisor/reduce-document-size/)

### Concurrent Requests Error

#### What happens if there are too many concurrent MongoDB Search index management requests?

If there are too many concurrent index creation or other index management operation requests, MongoDB Search returns the following error:

```shell
Too many concurrent requests. Please try again later.
```

We recommend trying again after some time.

## Create a MongoDB Search Index

To create a MongoDB Search index through the [Node Driver:](https://www.mongodb.com/docs/drivers/node/current/)

1. Define the search index from your application.

2. Run the `createSearchIndex` or `createSearchIndexes` helper method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the indexes, call the `listSearchIndexes()` method on your collection.

1. Create a file named `create-index.js`.

2. Define the search index.

   ### Create One Search Index

   Replace the placeholder values in the following example application named `create-index.js`, which uses the `createSearchIndex` command to define a MongoDB Search index:

   | Value | Description |
   | --- | --- |
   | `<connectionString>` | Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver) |
   | `<databaseName>` | Database for which you want to create the index. |
   | `<collectionName>` | Collection for which you want to create the index. |
   | `<indexName>` | Name of your index. If you omit the index name, MongoDB Search names the index `default`. |
   | `<IndexDefinition>` | The definition of your index. To learn about index definition syntax, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions) |

   ```javascript
   import { MongoClient } from "mongodb";

   // connect to your Atlas deployment
   const uri =  "<connectionString>";

   const client = new MongoClient(uri);

   async function run() {
     try {
       const database = client.db("<databaseName>");
       const collection = database.collection("<collectionName>");
       
       // define your MongoDB Search index
       const index = {
           name: "<indexName>",
           definition: {
               /* search index definition fields */
               <indexDefinition>
           }
       }

       // run the helper method
       const result = await collection.createSearchIndex(index);
       console.log(result);
     } finally {
       await client.close();
     }
   }
   run().catch(console.dir);

   ```

3. Run the sample application to create the index.

   Use the following command:

   ```shell
   node create-index.js
   ```

   **Output:**

   ```text
   <index-name>
   ```

## View MongoDB Search Indexes

To retrieve your MongoDB Search indexes through the [Node Driver](https://www.mongodb.com/docs/drivers/node/current/), use the `listSearchIndexes` helper method.

### Example

You can use the following sample application named `list-indexes.js` to return the indexes on your collection. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection that contains the search indexes that you want to retrieve.

- The index name if you want to retrieve a specific index. To return all indexes on the collection, omit this value.

**Note:**

The `listSearchIndexes` command returns a cursor. As a result, it doesn't immediately return the indexes matched by the command. To access the results, use a cursor paradigm such as the `toArray()` method. To learn more, see [Access Data From a Cursor.](https://www.mongodb.com/docs/drivers/node/current/fundamentals/crud/read-operations/cursor/)

```javascript
import { MongoClient } from "mongodb";

// connect to your Atlas deployment
const uri =  "<connection-string>";

const client = new MongoClient(uri);

async function run() {
  try {
    const database = client.db("<databaseName>");
    const collection = database.collection("<collectionName>");

    // run the helper method
    const result = await collection.listSearchIndexes("<index-name>").toArray();
    console.log(result);
  } finally {
    await client.close();
  }
}
run().catch(console.dir);

```

To run the sample application, use the following command. Your results should resemble the example output:

```shell
node list-indexes.js
```

**Output:**

```json
[
   {
      id: '648b4ad4d697b73bf9d2e5e0',
      name: 'default',
      status: 'READY',
      queryable: true,
      latestDefinition: { mappings: { dynamic: true } }
   },
   {
      id: '648b4ad4d697b73bf9d2e5e1',
      name: 'example-index',
      status: 'PENDING',
      queryable: false,
      latestDefinition: {
         mappings: { dynamic: false, fields: { text: { type: 'string' } } }
      }
   }
]
```

## Edit a MongoDB Search Index

To edit a MongoDB Search index through the [Node Driver](https://www.mongodb.com/docs/drivers/node/current/), use the `updateSearchIndex` helper method.

### Example

You can use the following sample application named `update-index.js` to update an existing index definition. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection where you created the search index.

- The new index definition to replace the existing definition. In the example, you update an index to use [static mappings](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings). You can alter this definition to suit your specific indexing needs. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

- The name of the index that you want to update.

```javascript
import { MongoClient } from "mongodb";

// connect to your Atlas deployment
const uri =  "<connection-string>";

const client = new MongoClient(uri);

async function run() {
  try {
    const database = client.db("<databaseName>");
    const collection = database.collection("<collectionName>");

    // define your MongoDB Search index
    const index = {
        /* updated search index definition */
        "mappings": {
            "dynamic": false,
            "fields": {
              "<field-name>": {
                "type": "<field-type>"
              }
            }
        }
    }

    // run the helper method
    await collection.updateSearchIndex("<index-name>", index);
  } finally {
    await client.close();
  }
}
run().catch(console.dir);

```

To run the sample application, use the following command:

```text
node update-index.js
```

**Note:**

The `updateSearchIndex()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index through the [Node Driver](https://www.mongodb.com/docs/drivers/node/current/), use the `dropSearchIndex` helper method.

### Example

You can use the following sample application named `drop-index.js` to delete an index on your collection. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection where you created the search index.

- The name of the index that you want to delete.

```javascript
// connect to your Atlas deployment
const uri = "<connection-string>";

const client = new MongoClient(uri);

async function run() {
  try {
    const database = client.db("<databaseName>");
    const collection = database.collection("<collectionName>");

    // run the helper method
    await collection.dropSearchIndex("<index-name>");
    
  } finally {
    await client.close();
  }
}
run().catch(console.dir);

```

To run the sample application, use the following command.

```text
node drop-index.js
```

**Note:**

The `dropSearchIndex()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

## Create a MongoDB Search Index

To create a MongoDB Search index through the [Node Driver:](https://www.mongodb.com/docs/drivers/node/current/)

1. Define the search index from your application.

2. Run the `createSearchIndex` or `createSearchIndexes` helper method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the indexes, call the `listSearchIndexes()` method on your collection.

1. Create a file named `create-index.js`.

2. Define the search index.

   ### Create One Search Index

   Replace the placeholder values in the following example application named `create-index.js`, which uses the `createSearchIndex` command to define a MongoDB Search index:

   | Value | Description |
   | --- | --- |
   | `<connectionString>` | Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver) |
   | `<databaseName>` | Database for which you want to create the index. |
   | `<collectionName>` | Collection for which you want to create the index. |
   | `<indexName>` | Name of your index. If you omit the index name, MongoDB Search names the index `default`. |
   | `<IndexDefinition>` | The definition of your index. To learn about index definition syntax, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions) |

   ```javascript
   import { MongoClient } from "mongodb";

   // connect to your Atlas deployment
   const uri =  "<connectionString>";

   const client = new MongoClient(uri);

   async function run() {
     try {
       const database = client.db("<databaseName>");
       const collection = database.collection("<collectionName>");
       
       // define your MongoDB Search index
       const index = {
           name: "<indexName>",
           definition: {
               /* search index definition fields */
               <indexDefinition>
           }
       }

       // run the helper method
       const result = await collection.createSearchIndex(index);
       console.log(result);
     } finally {
       await client.close();
     }
   }
   run().catch(console.dir);

   ```

3. Run the sample application to create the index.

   Use the following command:

   ```shell
   node create-index.js
   ```

   **Output:**

   ```text
   <index-name>
   ```

## View MongoDB Search Indexes

To retrieve your MongoDB Search indexes through the [Node Driver](https://www.mongodb.com/docs/drivers/node/current/), use the `listSearchIndexes` helper method.

### Example

You can use the following sample application named `list-indexes.js` to return the indexes on your collection. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection that contains the search indexes that you want to retrieve.

- The index name if you want to retrieve a specific index. To return all indexes on the collection, omit this value.

**Note:**

The `listSearchIndexes` command returns a cursor. As a result, it doesn't immediately return the indexes matched by the command. To access the results, use a cursor paradigm such as the `toArray()` method. To learn more, see [Access Data From a Cursor.](https://www.mongodb.com/docs/drivers/node/current/fundamentals/crud/read-operations/cursor/)

```javascript
import { MongoClient } from "mongodb";

// connect to your Atlas deployment
const uri =  "<connection-string>";

const client = new MongoClient(uri);

async function run() {
  try {
    const database = client.db("<databaseName>");
    const collection = database.collection("<collectionName>");

    // run the helper method
    const result = await collection.listSearchIndexes("<index-name>").toArray();
    console.log(result);
  } finally {
    await client.close();
  }
}
run().catch(console.dir);

```

To run the sample application, use the following command. Your results should resemble the example output:

```shell
node list-indexes.js
```

**Output:**

```json
[
   {
      id: '648b4ad4d697b73bf9d2e5e0',
      name: 'default',
      status: 'READY',
      queryable: true,
      latestDefinition: { mappings: { dynamic: true } }
   },
   {
      id: '648b4ad4d697b73bf9d2e5e1',
      name: 'example-index',
      status: 'PENDING',
      queryable: false,
      latestDefinition: {
         mappings: { dynamic: false, fields: { text: { type: 'string' } } }
      }
   }
]
```

## Edit a MongoDB Search Index

To edit a MongoDB Search index through the [Node Driver](https://www.mongodb.com/docs/drivers/node/current/), use the `updateSearchIndex` helper method.

### Example

You can use the following sample application named `update-index.js` to update an existing index definition. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection where you created the search index.

- The new index definition to replace the existing definition. In the example, you update an index to use [static mappings](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings). You can alter this definition to suit your specific indexing needs. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

- The name of the index that you want to update.

```javascript
import { MongoClient } from "mongodb";

// connect to your Atlas deployment
const uri =  "<connection-string>";

const client = new MongoClient(uri);

async function run() {
  try {
    const database = client.db("<databaseName>");
    const collection = database.collection("<collectionName>");

    // define your MongoDB Search index
    const index = {
        /* updated search index definition */
        "mappings": {
            "dynamic": false,
            "fields": {
              "<field-name>": {
                "type": "<field-type>"
              }
            }
        }
    }

    // run the helper method
    await collection.updateSearchIndex("<index-name>", index);
  } finally {
    await client.close();
  }
}
run().catch(console.dir);

```

To run the sample application, use the following command:

```text
node update-index.js
```

**Note:**

The `updateSearchIndex()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index through the [Node Driver](https://www.mongodb.com/docs/drivers/node/current/), use the `dropSearchIndex` helper method.

### Example

You can use the following sample application named `drop-index.js` to delete an index on your collection. Specify the following values:

- Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

- The database and collection where you created the search index.

- The name of the index that you want to delete.

```javascript
// connect to your Atlas deployment
const uri = "<connection-string>";

const client = new MongoClient(uri);

async function run() {
  try {
    const database = client.db("<databaseName>");
    const collection = database.collection("<collectionName>");

    // run the helper method
    await collection.dropSearchIndex("<index-name>");
    
  } finally {
    await client.close();
  }
}
run().catch(console.dir);

```

To run the sample application, use the following command.

```text
node drop-index.js
```

**Note:**

The `dropSearchIndex()` method doesn't return an output. To view your [index status](https://www.mongodb.com/docs/manual/reference/method/db.collection.getSearchIndexes.md#std-label-search-index-status), you can use the Atlas CLI to list MongoDB Search indexes. To learn more, see [atlas clusters search index list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-search-indexes-list/) or [atlas deployments search index list.](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-deployments-search-indexes-list/)

## Create a MongoDB Search Index

To create a MongoDB Search index using the [Java Driver:](https://www.mongodb.com/docs/drivers/java/sync/current/)

1. Construct a document that defines the search index

2. Pass the document to the `createSearchIndex()` or `createSearchIndexes()` method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the indexes, call the `listSearchIndexes()` method on your collection.

1. Create a new file named `CreateIndex.java`.

2. Copy the following code example into the file.

   ### Create One Search Index

   The following sample application defines a search index to dynamically index the fields in your collection, and then runs the `createSearchIndex()` method to create the index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

   ```java
   import com.mongodb.client.MongoClient;
   import com.mongodb.client.MongoClients;
   import com.mongodb.client.MongoCollection;
   import com.mongodb.client.MongoDatabase;
   import org.bson.Document;

   public class CreateIndex {
       public static void main(String[] args) {
           // connect to your Atlas cluster
           String uri = "<connection-string>";

           try (MongoClient mongoClient = MongoClients.create(uri)) {
               // set namespace
               MongoDatabase database = mongoClient.getDatabase("<databaseName>");
               MongoCollection<Document> collection = database.getCollection("<collectionName>");

               Document index = new Document("mappings",
                       new Document("dynamic", true));
               collection.createSearchIndex("<index-name>", index);
           }
       }
   }

   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to create the index.

   - The names of your indexes. If you omit an index's name, MongoDB Search names the index `default`.

   ### Create One Search Index

4. Compile and run the file.

   ```shell
   javac CreateIndex.java
   java CreateIndex
   ```

## View MongoDB Search Indexes

To use the [Java Driver](https://www.mongodb.com/docs/drivers/java/sync/current/) to retrieve your MongoDB Search indexes on a collection:

1. Create a new file named `ViewIndex.java`.

2. Copy the following code example into the file.

   The following sample application retrieves all MongoDB Search indexes on a given collection.

   ```java
   import com.mongodb.client.MongoClient;
   import com.mongodb.client.MongoClients;
   import com.mongodb.client.MongoCollection;
   import com.mongodb.client.MongoCursor;
   import com.mongodb.client.MongoDatabase;
   import org.bson.Document;
   public class ViewIndex {
       public static void main(String[] args) {
           // connect to your Atlas cluster
           String uri = "<connection-string>";
           try (MongoClient mongoClient = MongoClients.create(uri)) {
               // set namespace
               MongoDatabase database = mongoClient.getDatabase("<database-name>");
               MongoCollection<Document> collection = database.getCollection("<collection-name>");
               // retrieve indexes
               try (MongoCursor<Document> resultsCursor = collection.listSearchIndexes().iterator()) {
                   while (resultsCursor.hasNext()) {
                       System.out.println(resultsCursor.next());
                   }
               }
           }
       }
   }
   ```

3. Replace the following values and then save the file.

   - `<connection-string>`: Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - `<database-name>` and  `<collection-name>`: - The name of the database and collection for which you want to retrieve the index.

4. Compile and run the file.

   ```shell
   javac ViewIndex.java
   java ViewIndex
   ```

**See also:**

[MongoDB Search Indexes](https://www.mongodb.com/docs/drivers/java/sync/current/indexes/#atlas-search-indexes)

## Edit a MongoDB Search Index

To edit a MongoDB Search index using the [Java Driver:](https://www.mongodb.com/docs/drivers/java/sync/current/)

1. Create a new file named `EditIndex.java`.

2. Copy the following code example into the file.

   ```java
   import com.mongodb.client.MongoClient;
   import com.mongodb.client.MongoClients;
   import com.mongodb.client.MongoCollection;
   import com.mongodb.client.MongoDatabase;
   import org.bson.Document;

   public class EditIndex {
       public static void main(String[] args) {
           // connect to your Atlas cluster
           String uri = "<connection-string>";

           try (MongoClient mongoClient = MongoClients.create(uri)) {
               // set namespace
               MongoDatabase database = mongoClient.getDatabase("<document-name>");
               MongoCollection<Document> collection = database.getCollection("<collection-name>");
               // define field mappings
               Document index = new Document("analyzer", "<analyzer-name>").append(
                               "mappings", new Document("dynamic", <true|false>)
                                       .append("fields", new Document("<field-name>",
                                              new Document("type", "<field-type>"))));
               // run the updateSearchIndex() method
               collection.updateSearchIndex("<index-name>", index);
           }
       }
   }

   ```

3. Replace the following values in the code and then save the file.

   - `<connection-string>` - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

     IMPORTANT: In your connection string, don't include the [Write Concern](https://www.mongodb.com/docs/manual/reference/write-concern.md#std-label-write-concern) setting.

   - `<database-name>` - The name of the database that contains the collection.

   - `<collection-name>` - The name of the collection for which you want to retrieve the index.

   - `<analyzer-name>` - The name of the [analyzer.](https://www.mongodb.com/docs/search/indexes/analyzers/overview.md#std-label-analyzers-ref)

   - `dynamic` - The flag that indicates whether or not to [automatically](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings) index the fields.

   - `<field-name>` - The name of the field to index.

   - `<field-type>` - The field data [type.](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-bson-data-types)

   - `<index-name>` - The name of the index.

4. Compile and run the file.

   ```shell
   javac EditIndex.java
   java EditIndex
   ```

   The `updateSearchIndex()` method runs asynchronously. Use the `listSearchIndexes()` method to determine if the changes have been applied to your index. To learn more about retrieving MongoDB Search indexes, see [Manage MongoDB Search Indexes.](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-ref-view-index-programmatically)

**See also:**

[MongoDB Search Indexes](https://www.mongodb.com/docs/drivers/java/sync/current/indexes/#atlas-search-indexes)

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index on a collection using the [Java Driver](https://www.mongodb.com/docs/drivers/java/sync/current/indexes/#atlas-search-indexes), use the `dropSearchIndex()` method:

1. Create a new file named `DeleteIndex.java`.

2. Copy the following code example into the file.

   The following sample application deletes the specified MongoDB Search index on the specified collection.

   ```java
   import com.mongodb.client.MongoClient;
   import com.mongodb.client.MongoClients;
   import com.mongodb.client.MongoCollection;
   import com.mongodb.client.MongoDatabase;
   import org.bson.Document;

   public class DeleteIndex {
       public static void main(String[] args) {
           // connect to your Atlas cluster
           String uri = "<connection-string>";

           try (MongoClient mongoClient = MongoClients.create(uri)) {
               // set namespace
               MongoDatabase database = mongoClient.getDatabase("<database-name>");
               MongoCollection<Document> collection = database.getCollection("<collection>");
               // delete the index
               collection.dropSearchIndex("<index-name>");
           }
       }
   }

   ```

3. Replace the following values and then save the file.

   - `<connection-string>`: Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

     IMPORTANT: In your connection string, don't include the [Write Concern](https://www.mongodb.com/docs/manual/reference/write-concern.md#std-label-write-concern) setting.

   - `<database-name>`: The name of the database that contains the collection.

   - `<collection-name>`: The name of the collection for which you want to retrieve the index.

   - `<index-name>`: The name of the index to delete.

4. Compile and run the file.

   ```shell
   javac DeleteIndex.java
   java DeleteIndex
   ```

**See also:**

[MongoDB Search Indexes](https://www.mongodb.com/docs/drivers/java/sync/current/indexes/#atlas-search-indexes)

## Considerations for MongoDB Search Indexes

When creating and managing MongoDB Search indexes, consider the following:

### Index Consistency and Rebuilding

#### When is query data consistent after updates?

If you make changes to the collection for which you defined MongoDB Search indexes, the latest data might not be available immediately for queries. However, `mongot` monitors the change streams, which allows it to update stored copies of data, and MongoDB Search indexes are eventually consistent.

When you change an index definition, `mongot` automatically rebuilds the new index in the background, while continuing to serve queries with the old index to make sure there is no downtime. It is recommended that you wait for the index build to complete before running any queries using new index definitions. Using the new index during its build process can lead to unexpected results or incomplete data. This happens when you deploy `mongot` and `mongod` processes on the same node and when you deploy the processes on different nodes. Atlas also rebuilds indexes when you enable or disable [Encryption at Rest.](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption)

If you change the topology of your search deployment, MongoDB Search provisions and builds indexes on any new nodes before removing old nodes, to ensure there is no query downtime.

For deployments where both the `mongod` and `mongot` processes run on the same node, if MongoDB Search introduces changes that require rebuilding your indexes (such as some MongoDB Search features that require an [index update](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-index-rebuild)), Atlas automatically deploys additional nodes for free to build the indexes, while the old nodes continue to serve your queries.

WARNING: If you shard a collection that already has a MongoDB Search index, you might experience a brief period of incomplete search results while the index is building on a shard. Also, if you add a shard for an already sharded collection that contains a MongoDB Search index, your search queries against that collection might return incomplete results until the initial sync process completes on the added shards. To learn more, see [initial sync process.](https://www.mongodb.com/docs/search/performance/index-performance.md#std-label-troubleshoot-initial-sync)

IMPORTANT: If you use the [$out](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/) aggregation stage to modify a collection with an existing MongoDB Search index, you must delete and re-create the search index. If possible, consider using [$merge](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/) instead of `$out`.

### Dedicated Search Nodes

#### How are MongoDB Search indexes affected by dedicated Search Node architecture?

You can deploy [dedicated Search Nodes](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-what-is-search-node) to improve performance, scalability, and resource isolation.

If you've deployed Search Nodes, consider the following:

- Adding and adjusting [shards](https://www.mongodb.com/docs/manual/sharding.md#std-label-sharding-background) triggers a rebuild of the MongoDB Search index. During this index rebuild, the index might not have the most current data. Therefore, queries against data on those shards might fail or return incorrect results.

- If you [reshard](https://www.mongodb.com/docs/manual/core/sharding-reshard-a-collection.md#std-label-sharding-resharding) a collection with MongoDB Search indexes, MongoDB Search indexes on the collection become unavailable when the resharding operation completes. You *must* manually rebuild the MongoDB Search indexes once the operation completes.

- If you issue the command to [change the primary shard](https://www.mongodb.com/docs/manual/reference/command/movePrimary/) of a database, the MongoDB Search indexes for any unsharded collection under this database become unavailable once the operation completes. You *must* delete and create new MongoDB Search indexes once the [`movePrimary`](https://www.mongodb.com/docs/manual/reference/command/movePrimary.md#mongodb-dbcommand-dbcmd.movePrimary) operation is complete.

- Scaling your cluster by adding search nodes or by changing the search tier triggers a rebuild of the full MongoDB Search index. However, if your cluster has dedicated search nodes for which you haven't enabled [Encryption at Rest using Customer Key Management](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption), Atlas provides the following optimizations:

  - When you scale your search nodes, Atlas uses a recent copy of your index in S3 (Simple Storage Service), Google Cloud Storage, or Azure Blob Storage instead of rebuilding the entire MongoDB Search index on the new node.

  - For existing nodes, Atlas periodically takes and uploads a new incremental list of index files. Atlas retains index files for up to fourteen (14) days.

To learn more about MongoDB Search node architecture, see [MongoDB Search Deployment Options.](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-fts-deployment-options)

### Disk, Memory, and Resource Usage

#### How do MongoDB Search indexes affect your available disk space and memory?

Although the data stored on MongoDB Search isn't an identical copy of data from the collection on your Atlas cluster, MongoDB Search indexes still take some disk space and memory. If you enable the `store` option for fields that contain [string](https://www.mongodb.com/docs/search/indexes/field-types/string-type.md#std-label-bson-data-types-string) values or if you configure the [stored source fields](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition) in your index, MongoDB Search stores an identical copy of the specified fields on disk, which can take disk space.

**Important:**

If your collection contains documents that are 16MB (BSON (Binary Javascript Object Notation) limit), MongoDB Search fails to index the document, causes your index to become [STALE](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-index-statuses), and requires a full index rebuild. This issue can also occur when update operations on documents cause the change stream event to exceed the 16MB BSON (Binary Javascript Object Notation) limit. To minimize the risk of your index becoming stale, ensure that documents in your collection don't exceed 8MB. If your index has become stale, you must delete the large document(s) from your collection in order for the index rebuild to complete.

In addition:

- Structure your documents to minimize the size of sub-documents or arrays.

- Avoid operations that update or replace large fields, sub-documents, or arrays.

To learn more, see [Change Streams Production Recommendations](https://www.mongodb.com/docs/manual/administration/change-streams-production-recommendations/) and [Reduce the Size of Large Documents.](https://www.mongodb.com/docs/ops-manager/current/schema-advisor/reduce-document-size/)

### Concurrent Requests Error

#### What happens if there are too many concurrent MongoDB Search index management requests?

If there are too many concurrent index creation or other index management operation requests, MongoDB Search returns the following error:

```shell
Too many concurrent requests. Please try again later.
```

We recommend trying again after some time.

## Create a MongoDB Search Index

To create a MongoDB Search index using the [Java Driver:](https://www.mongodb.com/docs/drivers/java/sync/current/)

1. Construct a document that defines the search index

2. Pass the document to the `createSearchIndex()` or `createSearchIndexes()` method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the indexes, call the `listSearchIndexes()` method on your collection.

1. Create a new file named `CreateIndex.java`.

2. Copy the following code example into the file.

   ### Create One Search Index

   The following sample application defines a search index to dynamically index the fields in your collection, and then runs the `createSearchIndex()` method to create the index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

   ```java
   import com.mongodb.client.MongoClient;
   import com.mongodb.client.MongoClients;
   import com.mongodb.client.MongoCollection;
   import com.mongodb.client.MongoDatabase;
   import org.bson.Document;

   public class CreateIndex {
       public static void main(String[] args) {
           // connect to your Atlas cluster
           String uri = "<connection-string>";

           try (MongoClient mongoClient = MongoClients.create(uri)) {
               // set namespace
               MongoDatabase database = mongoClient.getDatabase("<databaseName>");
               MongoCollection<Document> collection = database.getCollection("<collectionName>");

               Document index = new Document("mappings",
                       new Document("dynamic", true));
               collection.createSearchIndex("<index-name>", index);
           }
       }
   }

   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to create the index.

   - The names of your indexes. If you omit an index's name, MongoDB Search names the index `default`.

   ### Create One Search Index

4. Compile and run the file.

   ```shell
   javac CreateIndex.java
   java CreateIndex
   ```

## View MongoDB Search Indexes

To use the [Java Driver](https://www.mongodb.com/docs/drivers/java/sync/current/) to retrieve your MongoDB Search indexes on a collection:

1. Create a new file named `ViewIndex.java`.

2. Copy the following code example into the file.

   The following sample application retrieves all MongoDB Search indexes on a given collection.

   ```java
   import com.mongodb.client.MongoClient;
   import com.mongodb.client.MongoClients;
   import com.mongodb.client.MongoCollection;
   import com.mongodb.client.MongoCursor;
   import com.mongodb.client.MongoDatabase;
   import org.bson.Document;
   public class ViewIndex {
       public static void main(String[] args) {
           // connect to your Atlas cluster
           String uri = "<connection-string>";
           try (MongoClient mongoClient = MongoClients.create(uri)) {
               // set namespace
               MongoDatabase database = mongoClient.getDatabase("<database-name>");
               MongoCollection<Document> collection = database.getCollection("<collection-name>");
               // retrieve indexes
               try (MongoCursor<Document> resultsCursor = collection.listSearchIndexes().iterator()) {
                   while (resultsCursor.hasNext()) {
                       System.out.println(resultsCursor.next());
                   }
               }
           }
       }
   }
   ```

3. Replace the following values and then save the file.

   - `<connection-string>`: Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - `<database-name>` and  `<collection-name>`: - The name of the database and collection for which you want to retrieve the index.

4. Compile and run the file.

   ```shell
   javac ViewIndex.java
   java ViewIndex
   ```

**See also:**

[MongoDB Search Indexes](https://www.mongodb.com/docs/drivers/java/sync/current/indexes/#atlas-search-indexes)

## Edit a MongoDB Search Index

To edit a MongoDB Search index using the [Java Driver:](https://www.mongodb.com/docs/drivers/java/sync/current/)

1. Create a new file named `EditIndex.java`.

2. Copy the following code example into the file.

   ```java
   import com.mongodb.client.MongoClient;
   import com.mongodb.client.MongoClients;
   import com.mongodb.client.MongoCollection;
   import com.mongodb.client.MongoDatabase;
   import org.bson.Document;

   public class EditIndex {
       public static void main(String[] args) {
           // connect to your Atlas cluster
           String uri = "<connection-string>";

           try (MongoClient mongoClient = MongoClients.create(uri)) {
               // set namespace
               MongoDatabase database = mongoClient.getDatabase("<document-name>");
               MongoCollection<Document> collection = database.getCollection("<collection-name>");
               // define field mappings
               Document index = new Document("analyzer", "<analyzer-name>").append(
                               "mappings", new Document("dynamic", <true|false>)
                                       .append("fields", new Document("<field-name>",
                                              new Document("type", "<field-type>"))));
               // run the updateSearchIndex() method
               collection.updateSearchIndex("<index-name>", index);
           }
       }
   }

   ```

3. Replace the following values in the code and then save the file.

   - `<connection-string>` - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

     IMPORTANT: In your connection string, don't include the [Write Concern](https://www.mongodb.com/docs/manual/reference/write-concern.md#std-label-write-concern) setting.

   - `<database-name>` - The name of the database that contains the collection.

   - `<collection-name>` - The name of the collection for which you want to retrieve the index.

   - `<analyzer-name>` - The name of the [analyzer.](https://www.mongodb.com/docs/search/indexes/analyzers/overview.md#std-label-analyzers-ref)

   - `dynamic` - The flag that indicates whether or not to [automatically](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings) index the fields.

   - `<field-name>` - The name of the field to index.

   - `<field-type>` - The field data [type.](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-bson-data-types)

   - `<index-name>` - The name of the index.

4. Compile and run the file.

   ```shell
   javac EditIndex.java
   java EditIndex
   ```

   The `updateSearchIndex()` method runs asynchronously. Use the `listSearchIndexes()` method to determine if the changes have been applied to your index. To learn more about retrieving MongoDB Search indexes, see [Manage MongoDB Search Indexes.](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-ref-view-index-programmatically)

**See also:**

[MongoDB Search Indexes](https://www.mongodb.com/docs/drivers/java/sync/current/indexes/#atlas-search-indexes)

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index on a collection using the [Java Driver](https://www.mongodb.com/docs/drivers/java/sync/current/indexes/#atlas-search-indexes), use the `dropSearchIndex()` method:

1. Create a new file named `DeleteIndex.java`.

2. Copy the following code example into the file.

   The following sample application deletes the specified MongoDB Search index on the specified collection.

   ```java
   import com.mongodb.client.MongoClient;
   import com.mongodb.client.MongoClients;
   import com.mongodb.client.MongoCollection;
   import com.mongodb.client.MongoDatabase;
   import org.bson.Document;

   public class DeleteIndex {
       public static void main(String[] args) {
           // connect to your Atlas cluster
           String uri = "<connection-string>";

           try (MongoClient mongoClient = MongoClients.create(uri)) {
               // set namespace
               MongoDatabase database = mongoClient.getDatabase("<database-name>");
               MongoCollection<Document> collection = database.getCollection("<collection>");
               // delete the index
               collection.dropSearchIndex("<index-name>");
           }
       }
   }

   ```

3. Replace the following values and then save the file.

   - `<connection-string>`: Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

     IMPORTANT: In your connection string, don't include the [Write Concern](https://www.mongodb.com/docs/manual/reference/write-concern.md#std-label-write-concern) setting.

   - `<database-name>`: The name of the database that contains the collection.

   - `<collection-name>`: The name of the collection for which you want to retrieve the index.

   - `<index-name>`: The name of the index to delete.

4. Compile and run the file.

   ```shell
   javac DeleteIndex.java
   java DeleteIndex
   ```

**See also:**

[MongoDB Search Indexes](https://www.mongodb.com/docs/drivers/java/sync/current/indexes/#atlas-search-indexes)

## Create a MongoDB Search Index

To create a MongoDB Search index using the [Java Driver:](https://www.mongodb.com/docs/drivers/java/sync/current/)

1. Construct a document that defines the search index

2. Pass the document to the `createSearchIndex()` or `createSearchIndexes()` method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the indexes, call the `listSearchIndexes()` method on your collection.

1. Create a new file named `CreateIndex.java`.

2. Copy the following code example into the file.

   ### Create One Search Index

   The following sample application defines a search index to dynamically index the fields in your collection, and then runs the `createSearchIndex()` method to create the index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

   ```java
   import com.mongodb.client.MongoClient;
   import com.mongodb.client.MongoClients;
   import com.mongodb.client.MongoCollection;
   import com.mongodb.client.MongoDatabase;
   import org.bson.Document;

   public class CreateIndex {
       public static void main(String[] args) {
           // connect to your Atlas cluster
           String uri = "<connection-string>";

           try (MongoClient mongoClient = MongoClients.create(uri)) {
               // set namespace
               MongoDatabase database = mongoClient.getDatabase("<databaseName>");
               MongoCollection<Document> collection = database.getCollection("<collectionName>");

               Document index = new Document("mappings",
                       new Document("dynamic", true));
               collection.createSearchIndex("<index-name>", index);
           }
       }
   }

   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to create the index.

   - The names of your indexes. If you omit an index's name, MongoDB Search names the index `default`.

   ### Create One Search Index

4. Compile and run the file.

   ```shell
   javac CreateIndex.java
   java CreateIndex
   ```

## View MongoDB Search Indexes

To use the [Java Driver](https://www.mongodb.com/docs/drivers/java/sync/current/) to retrieve your MongoDB Search indexes on a collection:

1. Create a new file named `ViewIndex.java`.

2. Copy the following code example into the file.

   The following sample application retrieves all MongoDB Search indexes on a given collection.

   ```java
   import com.mongodb.client.MongoClient;
   import com.mongodb.client.MongoClients;
   import com.mongodb.client.MongoCollection;
   import com.mongodb.client.MongoCursor;
   import com.mongodb.client.MongoDatabase;
   import org.bson.Document;
   public class ViewIndex {
       public static void main(String[] args) {
           // connect to your Atlas cluster
           String uri = "<connection-string>";
           try (MongoClient mongoClient = MongoClients.create(uri)) {
               // set namespace
               MongoDatabase database = mongoClient.getDatabase("<database-name>");
               MongoCollection<Document> collection = database.getCollection("<collection-name>");
               // retrieve indexes
               try (MongoCursor<Document> resultsCursor = collection.listSearchIndexes().iterator()) {
                   while (resultsCursor.hasNext()) {
                       System.out.println(resultsCursor.next());
                   }
               }
           }
       }
   }
   ```

3. Replace the following values and then save the file.

   - `<connection-string>`: Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - `<database-name>` and  `<collection-name>`: - The name of the database and collection for which you want to retrieve the index.

4. Compile and run the file.

   ```shell
   javac ViewIndex.java
   java ViewIndex
   ```

**See also:**

[MongoDB Search Indexes](https://www.mongodb.com/docs/drivers/java/sync/current/indexes/#atlas-search-indexes)

## Edit a MongoDB Search Index

To edit a MongoDB Search index using the [Java Driver:](https://www.mongodb.com/docs/drivers/java/sync/current/)

1. Create a new file named `EditIndex.java`.

2. Copy the following code example into the file.

   ```java
   import com.mongodb.client.MongoClient;
   import com.mongodb.client.MongoClients;
   import com.mongodb.client.MongoCollection;
   import com.mongodb.client.MongoDatabase;
   import org.bson.Document;

   public class EditIndex {
       public static void main(String[] args) {
           // connect to your Atlas cluster
           String uri = "<connection-string>";

           try (MongoClient mongoClient = MongoClients.create(uri)) {
               // set namespace
               MongoDatabase database = mongoClient.getDatabase("<document-name>");
               MongoCollection<Document> collection = database.getCollection("<collection-name>");
               // define field mappings
               Document index = new Document("analyzer", "<analyzer-name>").append(
                               "mappings", new Document("dynamic", <true|false>)
                                       .append("fields", new Document("<field-name>",
                                              new Document("type", "<field-type>"))));
               // run the updateSearchIndex() method
               collection.updateSearchIndex("<index-name>", index);
           }
       }
   }

   ```

3. Replace the following values in the code and then save the file.

   - `<connection-string>` - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

     IMPORTANT: In your connection string, don't include the [Write Concern](https://www.mongodb.com/docs/manual/reference/write-concern.md#std-label-write-concern) setting.

   - `<database-name>` - The name of the database that contains the collection.

   - `<collection-name>` - The name of the collection for which you want to retrieve the index.

   - `<analyzer-name>` - The name of the [analyzer.](https://www.mongodb.com/docs/search/indexes/analyzers/overview.md#std-label-analyzers-ref)

   - `dynamic` - The flag that indicates whether or not to [automatically](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-static-dynamic-mappings) index the fields.

   - `<field-name>` - The name of the field to index.

   - `<field-type>` - The field data [type.](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-bson-data-types)

   - `<index-name>` - The name of the index.

4. Compile and run the file.

   ```shell
   javac EditIndex.java
   java EditIndex
   ```

   The `updateSearchIndex()` method runs asynchronously. Use the `listSearchIndexes()` method to determine if the changes have been applied to your index. To learn more about retrieving MongoDB Search indexes, see [Manage MongoDB Search Indexes.](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-ref-view-index-programmatically)

**See also:**

[MongoDB Search Indexes](https://www.mongodb.com/docs/drivers/java/sync/current/indexes/#atlas-search-indexes)

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index on a collection using the [Java Driver](https://www.mongodb.com/docs/drivers/java/sync/current/indexes/#atlas-search-indexes), use the `dropSearchIndex()` method:

1. Create a new file named `DeleteIndex.java`.

2. Copy the following code example into the file.

   The following sample application deletes the specified MongoDB Search index on the specified collection.

   ```java
   import com.mongodb.client.MongoClient;
   import com.mongodb.client.MongoClients;
   import com.mongodb.client.MongoCollection;
   import com.mongodb.client.MongoDatabase;
   import org.bson.Document;

   public class DeleteIndex {
       public static void main(String[] args) {
           // connect to your Atlas cluster
           String uri = "<connection-string>";

           try (MongoClient mongoClient = MongoClients.create(uri)) {
               // set namespace
               MongoDatabase database = mongoClient.getDatabase("<database-name>");
               MongoCollection<Document> collection = database.getCollection("<collection>");
               // delete the index
               collection.dropSearchIndex("<index-name>");
           }
       }
   }

   ```

3. Replace the following values and then save the file.

   - `<connection-string>`: Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

     IMPORTANT: In your connection string, don't include the [Write Concern](https://www.mongodb.com/docs/manual/reference/write-concern.md#std-label-write-concern) setting.

   - `<database-name>`: The name of the database that contains the collection.

   - `<collection-name>`: The name of the collection for which you want to retrieve the index.

   - `<index-name>`: The name of the index to delete.

4. Compile and run the file.

   ```shell
   javac DeleteIndex.java
   java DeleteIndex
   ```

**See also:**

[MongoDB Search Indexes](https://www.mongodb.com/docs/drivers/java/sync/current/indexes/#atlas-search-indexes)

## Create a MongoDB Search Index

To use the [Python Driver](https://www.mongodb.com/docs/drivers/python-drivers/) to create a MongoDB Search index, define the search index from your application and call the `create_search_index()` method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the search indexes, call the `list_search_indexes()` method on your collection.

1. Create a new file named `create_index.py`.

2. Copy the following code example into the file.

   ### Create One Search Index

   The following sample application defines a search index to dynamically index the fields in your collection. Then, the application calls the `create_search_index()` method on a collection to create the search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

   ```python
   from pymongo.mongo_client import MongoClient
   from pymongo.operations import SearchIndexModel

   def create_index():
       # Connect to your Atlas deployment
       uri = "<connectionString>"
       client = MongoClient(uri)

       # Access your database and collection
       database = client["<databaseName>"]
       collection = database["<collectionName>"]

       # Create your index model, then create the search index
       search_index_model = SearchIndexModel(
           definition={
               "mappings": {
                   "dynamic": True
               },
           },
           name="<indexName>",
       )

       result = collection.create_search_index(model=search_index_model)
       print(result)


   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to create the index.

   - The name of your index. If you omit the index name, MongoDB Search names the index `default`.

   ### Create One Search Index

4. Run the file by using the following command.

   ```shell
   python create_index.py
   ```

## View MongoDB Search Indexes

To use the [Python Driver](https://www.mongodb.com/docs/drivers/python-drivers/) to retrieve your MongoDB Search indexes, call the `list_search_indexes()` method on your collection.

### Example

1. Create a new file named `view_index.py`.

2. Copy the following code example into the file.

   The following sample application calls the `list_search_indexes()` method on a collection. This method returns a cursor from which the code accesses and prints each MongoDB Search index:

   ```python
   from pymongo.mongo_client import MongoClient

   def view_index():
       # Connect to your Atlas deployment
       uri = "<connectionString>"
       client = MongoClient(uri)

       # Access your database and collection
       database = client["<databaseName>"]
       collection = database["<collectionName>"]

       # Get a list of the collection's search indexes and print them
       cursor = collection.list_search_indexes()
       for index in cursor:
           print(index)
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to retrieve the indexes.

4. Run the file by using the following command.

   ```shell
   python view_index.py
   ```

## Edit a MongoDB Search Index

To use the [Python Driver](https://www.mongodb.com/docs/drivers/python-drivers/) to update your MongoDB Search indexes, call the `update_search_index()` method on your collection.

### Example

1. Create a new file named `edit_index.py`.

2. Copy the following code example into the file.

   The following sample application specifies a new MongoDB Search index definition. Then, the application passes this definition and an existing index name to the `update_search_index()` method, which updates the existing index to reflect the new definition document.

   ```python
   from pymongo.mongo_client import MongoClient

   def edit_index():
       # Connect to your Atlas deployment
       uri = "<connectionString>"
       client = MongoClient(uri)

       # Access your database and collection
       database = client["<databaseName>"]
       collection = database["<collectionName>"]

       # Specify a new index definition
       definition = {
               "mappings": {
                   "dynamic": True
               },
       }
       
       # Update your search index
       collection.update_search_index("<indexName>", definition)
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to update an index.

   - The name of the index that you want to update.

   - The fields to redefine your search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

4. Run the file using the following command.

   ```shell
   python edit_index.py
   ```

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To use the [Python Driver](https://www.mongodb.com/docs/drivers/python-drivers/) to delete your MongoDB Search index, call the `drop_search_index()` method on your collection.

### Example

1. Create a new file named `delete_index.py`.

2. Copy the following code example into the file.

   The following sample application passes a MongoDB Search index name to the `drop_search_index()` method to delete the index.

   ```python
   from pymongo.mongo_client import MongoClient

   def delete_index():
       # Connect to your Atlas deployment
       uri = "<connectionString>"
       client = MongoClient(uri)

       # Access your database and collection
       database = client["<databaseName>"]
       collection = database["<collectionName>"]

       # Delete your search index
       collection.drop_search_index("<indexName>")
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to delete an index.

   - The name of the index that you want to delete.

4. Run the file using the following command.

   ```shell
   python delete_index.py
   ```

## Considerations for MongoDB Search Indexes

When creating and managing MongoDB Search indexes, consider the following:

### Index Consistency and Rebuilding

#### When is query data consistent after updates?

If you make changes to the collection for which you defined MongoDB Search indexes, the latest data might not be available immediately for queries. However, `mongot` monitors the change streams, which allows it to update stored copies of data, and MongoDB Search indexes are eventually consistent.

When you change an index definition, `mongot` automatically rebuilds the new index in the background, while continuing to serve queries with the old index to make sure there is no downtime. It is recommended that you wait for the index build to complete before running any queries using new index definitions. Using the new index during its build process can lead to unexpected results or incomplete data. This happens when you deploy `mongot` and `mongod` processes on the same node and when you deploy the processes on different nodes. Atlas also rebuilds indexes when you enable or disable [Encryption at Rest.](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption)

If you change the topology of your search deployment, MongoDB Search provisions and builds indexes on any new nodes before removing old nodes, to ensure there is no query downtime.

For deployments where both the `mongod` and `mongot` processes run on the same node, if MongoDB Search introduces changes that require rebuilding your indexes (such as some MongoDB Search features that require an [index update](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-index-rebuild)), Atlas automatically deploys additional nodes for free to build the indexes, while the old nodes continue to serve your queries.

WARNING: If you shard a collection that already has a MongoDB Search index, you might experience a brief period of incomplete search results while the index is building on a shard. Also, if you add a shard for an already sharded collection that contains a MongoDB Search index, your search queries against that collection might return incomplete results until the initial sync process completes on the added shards. To learn more, see [initial sync process.](https://www.mongodb.com/docs/search/performance/index-performance.md#std-label-troubleshoot-initial-sync)

IMPORTANT: If you use the [$out](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/) aggregation stage to modify a collection with an existing MongoDB Search index, you must delete and re-create the search index. If possible, consider using [$merge](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/) instead of `$out`.

### Dedicated Search Nodes

#### How are MongoDB Search indexes affected by dedicated Search Node architecture?

You can deploy [dedicated Search Nodes](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-what-is-search-node) to improve performance, scalability, and resource isolation.

If you've deployed Search Nodes, consider the following:

- Adding and adjusting [shards](https://www.mongodb.com/docs/manual/sharding.md#std-label-sharding-background) triggers a rebuild of the MongoDB Search index. During this index rebuild, the index might not have the most current data. Therefore, queries against data on those shards might fail or return incorrect results.

- If you [reshard](https://www.mongodb.com/docs/manual/core/sharding-reshard-a-collection.md#std-label-sharding-resharding) a collection with MongoDB Search indexes, MongoDB Search indexes on the collection become unavailable when the resharding operation completes. You *must* manually rebuild the MongoDB Search indexes once the operation completes.

- If you issue the command to [change the primary shard](https://www.mongodb.com/docs/manual/reference/command/movePrimary/) of a database, the MongoDB Search indexes for any unsharded collection under this database become unavailable once the operation completes. You *must* delete and create new MongoDB Search indexes once the [`movePrimary`](https://www.mongodb.com/docs/manual/reference/command/movePrimary.md#mongodb-dbcommand-dbcmd.movePrimary) operation is complete.

- Scaling your cluster by adding search nodes or by changing the search tier triggers a rebuild of the full MongoDB Search index. However, if your cluster has dedicated search nodes for which you haven't enabled [Encryption at Rest using Customer Key Management](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption), Atlas provides the following optimizations:

  - When you scale your search nodes, Atlas uses a recent copy of your index in S3 (Simple Storage Service), Google Cloud Storage, or Azure Blob Storage instead of rebuilding the entire MongoDB Search index on the new node.

  - For existing nodes, Atlas periodically takes and uploads a new incremental list of index files. Atlas retains index files for up to fourteen (14) days.

To learn more about MongoDB Search node architecture, see [MongoDB Search Deployment Options.](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-fts-deployment-options)

### Disk, Memory, and Resource Usage

#### How do MongoDB Search indexes affect your available disk space and memory?

Although the data stored on MongoDB Search isn't an identical copy of data from the collection on your Atlas cluster, MongoDB Search indexes still take some disk space and memory. If you enable the `store` option for fields that contain [string](https://www.mongodb.com/docs/search/indexes/field-types/string-type.md#std-label-bson-data-types-string) values or if you configure the [stored source fields](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition) in your index, MongoDB Search stores an identical copy of the specified fields on disk, which can take disk space.

**Important:**

If your collection contains documents that are 16MB (BSON (Binary Javascript Object Notation) limit), MongoDB Search fails to index the document, causes your index to become [STALE](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-index-statuses), and requires a full index rebuild. This issue can also occur when update operations on documents cause the change stream event to exceed the 16MB BSON (Binary Javascript Object Notation) limit. To minimize the risk of your index becoming stale, ensure that documents in your collection don't exceed 8MB. If your index has become stale, you must delete the large document(s) from your collection in order for the index rebuild to complete.

In addition:

- Structure your documents to minimize the size of sub-documents or arrays.

- Avoid operations that update or replace large fields, sub-documents, or arrays.

To learn more, see [Change Streams Production Recommendations](https://www.mongodb.com/docs/manual/administration/change-streams-production-recommendations/) and [Reduce the Size of Large Documents.](https://www.mongodb.com/docs/ops-manager/current/schema-advisor/reduce-document-size/)

### Concurrent Requests Error

#### What happens if there are too many concurrent MongoDB Search index management requests?

If there are too many concurrent index creation or other index management operation requests, MongoDB Search returns the following error:

```shell
Too many concurrent requests. Please try again later.
```

We recommend trying again after some time.

## Create a MongoDB Search Index

To use the [Python Driver](https://www.mongodb.com/docs/drivers/python-drivers/) to create a MongoDB Search index, define the search index from your application and call the `create_search_index()` method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the search indexes, call the `list_search_indexes()` method on your collection.

1. Create a new file named `create_index.py`.

2. Copy the following code example into the file.

   ### Create One Search Index

   The following sample application defines a search index to dynamically index the fields in your collection. Then, the application calls the `create_search_index()` method on a collection to create the search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

   ```python
   from pymongo.mongo_client import MongoClient
   from pymongo.operations import SearchIndexModel

   def create_index():
       # Connect to your Atlas deployment
       uri = "<connectionString>"
       client = MongoClient(uri)

       # Access your database and collection
       database = client["<databaseName>"]
       collection = database["<collectionName>"]

       # Create your index model, then create the search index
       search_index_model = SearchIndexModel(
           definition={
               "mappings": {
                   "dynamic": True
               },
           },
           name="<indexName>",
       )

       result = collection.create_search_index(model=search_index_model)
       print(result)


   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to create the index.

   - The name of your index. If you omit the index name, MongoDB Search names the index `default`.

   ### Create One Search Index

4. Run the file by using the following command.

   ```shell
   python create_index.py
   ```

## View MongoDB Search Indexes

To use the [Python Driver](https://www.mongodb.com/docs/drivers/python-drivers/) to retrieve your MongoDB Search indexes, call the `list_search_indexes()` method on your collection.

### Example

1. Create a new file named `view_index.py`.

2. Copy the following code example into the file.

   The following sample application calls the `list_search_indexes()` method on a collection. This method returns a cursor from which the code accesses and prints each MongoDB Search index:

   ```python
   from pymongo.mongo_client import MongoClient

   def view_index():
       # Connect to your Atlas deployment
       uri = "<connectionString>"
       client = MongoClient(uri)

       # Access your database and collection
       database = client["<databaseName>"]
       collection = database["<collectionName>"]

       # Get a list of the collection's search indexes and print them
       cursor = collection.list_search_indexes()
       for index in cursor:
           print(index)
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to retrieve the indexes.

4. Run the file by using the following command.

   ```shell
   python view_index.py
   ```

## Edit a MongoDB Search Index

To use the [Python Driver](https://www.mongodb.com/docs/drivers/python-drivers/) to update your MongoDB Search indexes, call the `update_search_index()` method on your collection.

### Example

1. Create a new file named `edit_index.py`.

2. Copy the following code example into the file.

   The following sample application specifies a new MongoDB Search index definition. Then, the application passes this definition and an existing index name to the `update_search_index()` method, which updates the existing index to reflect the new definition document.

   ```python
   from pymongo.mongo_client import MongoClient

   def edit_index():
       # Connect to your Atlas deployment
       uri = "<connectionString>"
       client = MongoClient(uri)

       # Access your database and collection
       database = client["<databaseName>"]
       collection = database["<collectionName>"]

       # Specify a new index definition
       definition = {
               "mappings": {
                   "dynamic": True
               },
       }
       
       # Update your search index
       collection.update_search_index("<indexName>", definition)
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to update an index.

   - The name of the index that you want to update.

   - The fields to redefine your search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

4. Run the file using the following command.

   ```shell
   python edit_index.py
   ```

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To use the [Python Driver](https://www.mongodb.com/docs/drivers/python-drivers/) to delete your MongoDB Search index, call the `drop_search_index()` method on your collection.

### Example

1. Create a new file named `delete_index.py`.

2. Copy the following code example into the file.

   The following sample application passes a MongoDB Search index name to the `drop_search_index()` method to delete the index.

   ```python
   from pymongo.mongo_client import MongoClient

   def delete_index():
       # Connect to your Atlas deployment
       uri = "<connectionString>"
       client = MongoClient(uri)

       # Access your database and collection
       database = client["<databaseName>"]
       collection = database["<collectionName>"]

       # Delete your search index
       collection.drop_search_index("<indexName>")
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to delete an index.

   - The name of the index that you want to delete.

4. Run the file using the following command.

   ```shell
   python delete_index.py
   ```

## Create a MongoDB Search Index

To use the [Python Driver](https://www.mongodb.com/docs/drivers/python-drivers/) to create a MongoDB Search index, define the search index from your application and call the `create_search_index()` method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the search indexes, call the `list_search_indexes()` method on your collection.

1. Create a new file named `create_index.py`.

2. Copy the following code example into the file.

   ### Create One Search Index

   The following sample application defines a search index to dynamically index the fields in your collection. Then, the application calls the `create_search_index()` method on a collection to create the search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

   ```python
   from pymongo.mongo_client import MongoClient
   from pymongo.operations import SearchIndexModel

   def create_index():
       # Connect to your Atlas deployment
       uri = "<connectionString>"
       client = MongoClient(uri)

       # Access your database and collection
       database = client["<databaseName>"]
       collection = database["<collectionName>"]

       # Create your index model, then create the search index
       search_index_model = SearchIndexModel(
           definition={
               "mappings": {
                   "dynamic": True
               },
           },
           name="<indexName>",
       )

       result = collection.create_search_index(model=search_index_model)
       print(result)


   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to create the index.

   - The name of your index. If you omit the index name, MongoDB Search names the index `default`.

   ### Create One Search Index

4. Run the file by using the following command.

   ```shell
   python create_index.py
   ```

## View MongoDB Search Indexes

To use the [Python Driver](https://www.mongodb.com/docs/drivers/python-drivers/) to retrieve your MongoDB Search indexes, call the `list_search_indexes()` method on your collection.

### Example

1. Create a new file named `view_index.py`.

2. Copy the following code example into the file.

   The following sample application calls the `list_search_indexes()` method on a collection. This method returns a cursor from which the code accesses and prints each MongoDB Search index:

   ```python
   from pymongo.mongo_client import MongoClient

   def view_index():
       # Connect to your Atlas deployment
       uri = "<connectionString>"
       client = MongoClient(uri)

       # Access your database and collection
       database = client["<databaseName>"]
       collection = database["<collectionName>"]

       # Get a list of the collection's search indexes and print them
       cursor = collection.list_search_indexes()
       for index in cursor:
           print(index)
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to retrieve the indexes.

4. Run the file by using the following command.

   ```shell
   python view_index.py
   ```

## Edit a MongoDB Search Index

To use the [Python Driver](https://www.mongodb.com/docs/drivers/python-drivers/) to update your MongoDB Search indexes, call the `update_search_index()` method on your collection.

### Example

1. Create a new file named `edit_index.py`.

2. Copy the following code example into the file.

   The following sample application specifies a new MongoDB Search index definition. Then, the application passes this definition and an existing index name to the `update_search_index()` method, which updates the existing index to reflect the new definition document.

   ```python
   from pymongo.mongo_client import MongoClient

   def edit_index():
       # Connect to your Atlas deployment
       uri = "<connectionString>"
       client = MongoClient(uri)

       # Access your database and collection
       database = client["<databaseName>"]
       collection = database["<collectionName>"]

       # Specify a new index definition
       definition = {
               "mappings": {
                   "dynamic": True
               },
       }
       
       # Update your search index
       collection.update_search_index("<indexName>", definition)
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to update an index.

   - The name of the index that you want to update.

   - The fields to redefine your search index. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

4. Run the file using the following command.

   ```shell
   python edit_index.py
   ```

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To use the [Python Driver](https://www.mongodb.com/docs/drivers/python-drivers/) to delete your MongoDB Search index, call the `drop_search_index()` method on your collection.

### Example

1. Create a new file named `delete_index.py`.

2. Copy the following code example into the file.

   The following sample application passes a MongoDB Search index name to the `drop_search_index()` method to delete the index.

   ```python
   from pymongo.mongo_client import MongoClient

   def delete_index():
       # Connect to your Atlas deployment
       uri = "<connectionString>"
       client = MongoClient(uri)

       # Access your database and collection
       database = client["<databaseName>"]
       collection = database["<collectionName>"]

       # Delete your search index
       collection.drop_search_index("<indexName>")
   ```

3. Specify the following values and save the file.

   - Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - The database and collection for which you want to delete an index.

   - The name of the index that you want to delete.

4. Run the file using the following command.

   ```shell
   python delete_index.py
   ```

## Create a MongoDB Search Index

To create a MongoDB Search index through the [Go Driver:](https://www.mongodb.com/docs/drivers/go/current/)

1. Define the search index from your application.

2. Run the `createOne()` helper method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the search indexes, call the `SearchIndexes().List()` method on your collection.

1. Create a new file named `create-index.go`.

2. Copy the following code example into the file.

   The following sample application creates a MongoDB Search index on a collection.

   ```go
   package main

   import (
   	"context"
   	"log"

   	"go.mongodb.org/mongo-driver/v2/bson"
   	"go.mongodb.org/mongo-driver/v2/mongo"
   	"go.mongodb.org/mongo-driver/v2/mongo/options"
   )

   func main() {
   	ctx := context.Background()

   	// Replace the placeholder with your Atlas connection string
   	const uri = "<connection-string>"

   	// Connect to your Atlas cluster
   	clientOptions := options.Client().ApplyURI(uri)
   	client, err := mongo.Connect(clientOptions)
   	if err != nil {
   		log.Fatalf("failed to connect to the server: %v", err)
   	}
   	defer func() { _ = client.Disconnect(ctx) }()

   	// Set the namespace
   	coll := client.Database("<database-name>").Collection("<collection-name>")

   	// Define a simple MongoDB Search index
   	indexName := "<index-name>"

   	// Create the default definition for search index
   	definition := bson.D{{"mappings", bson.D{{"dynamic", true}}}}
   	indexModel := mongo.SearchIndexModel{
   		Definition: definition,
   		Options:    options.SearchIndexes().SetName(indexName),
   	}

   	// Create the index
   	searchIndexName, err := coll.SearchIndexes().CreateOne(ctx, indexModel)
   	if err != nil {
   		log.Fatalf("failed to create the search index: %v", err)
   	}
   	log.Println("New search index named " + searchIndexName + " is building.")
   }

   ```

3. Replace the following values and then save the file.

   - `<connection-string>`: Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - `<database-name>` and  `<collection-name>`: The names of the database and collection for which you want to retrieve the index.

   - `<index-name>`: The name of your index. If you omit the index name, MongoDB Search names the index `default`.

4. Run the file.

   ```text
   go run create-index.go
   ```

## View MongoDB Search Indexes

To use the [Go Driver](https://www.mongodb.com/docs/drivers/go/current/) to retrieve a MongoDB Search index by specifying the index name:

1. Create a new file named `view-index.go`.

2. Copy the following code example into the file.

   The following sample application retrieves a MongoDB Search index by name from the specified collection.

   ```go
   package main

   import (
   	"context"
   	"encoding/json"
   	"fmt"
   	"log"

   	"go.mongodb.org/mongo-driver/v2/bson"
   	"go.mongodb.org/mongo-driver/v2/mongo"
   	"go.mongodb.org/mongo-driver/v2/mongo/options"
   )

   func main() {
   	ctx := context.Background()

   	// Replace the placeholder with your Atlas connection string
   	const uri = "<connection-string>"

   	// Connect to your Atlas cluster
   	clientOptions := options.Client().ApplyURI(uri)
   	client, err := mongo.Connect(clientOptions)
   	if err != nil {
   		log.Fatalf("failed to connect to the server: %v", err)
   	}
   	defer func() { _ = client.Disconnect(ctx) }()

   	// Set the namespace
   	coll := client.Database("<database-name>").Collection("<collection-name>")

   	// Specifies the index to retrieve
   	const indexName = "<index-name>"
   	opts := options.SearchIndexes().SetName(indexName)

   	// Retrieves the details of the specified index
   	cursor, err := coll.SearchIndexes().List(ctx, opts)
   	if err != nil {
   		log.Fatalf("failed to retrieve search index: %v", err)
   	}

   	// Prints the index details to the console as JSON
   	var results []bson.D
   	if err := cursor.All(ctx, &results); err != nil {
   		log.Fatalf("failed to unmarshal results to bson: %v", err)
   	}
   	jsonResults, err := json.Marshal(results)
   	if err != nil {
   		log.Fatalf("failed to marshal results to json: %v", err)
   	}
   	fmt.Println(string(jsonResults))
   }

   ```

3. Replace the following values and then save the file.

   - `<collection-name>` - The name of the collection for which you want to retrieve the index.

   - `<database-name>` and  `<collection-name>`: The names of the database and collection for which you want to retrieve the index.

   - `<index-name>`: The name of the index you want to retrieve.

4. Run the file.

   ```shell
   go run view-index.go
   ```

## Edit a MongoDB Search Index

To edit a MongoDB Search index using the [Go Driver:](https://www.mongodb.com/docs/drivers/go/current/)

1. Create a new file named `edit-index.go`.

2. Copy the following code example into the file.

   The following sample application edits a MongoDB Search index on the specified collection.

   ```go
   package main

   import (
   	"context"
   	"log"

   	"go.mongodb.org/mongo-driver/v2/bson"
   	"go.mongodb.org/mongo-driver/v2/mongo"
   	"go.mongodb.org/mongo-driver/v2/mongo/options"
   )

   func main() {
   	ctx := context.Background()

   	// Replace the placeholder with your Atlas connection string
   	const uri = "<connection-string>"

   	// Connect to your Atlas cluster
   	clientOptions := options.Client().ApplyURI(uri)
   	client, err := mongo.Connect(clientOptions)
   	if err != nil {
   		log.Fatalf("failed to connect to the server: %v", err)
   	}
   	defer func() { _ = client.Disconnect(ctx) }()

   	// Set the namespace
   	coll := client.Database("<database-name>").Collection("<collection-name>")

   	// Specifies the index name and the new index definition
   	const indexName = "<index-name>"

   	// Define the new index definition
   	definition := bson.D{<index-definition>}

   	// Updates the specified index
   	err = coll.SearchIndexes().UpdateOne(ctx, indexName, definition)
   	if err != nil {
   		log.Fatalf("Failed to update the index: %v", err)
   	}
   }

   ```

3. Replace the following values and then save the file.

   - `<connection-string>`: Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - `<database-name>` and  `<collection-name>`: The names of the database and collection for which you want to retrieve the index.

   - `<index-name>`: The name of the index you want to edit.

   - `<index-definition>`: The new search index definition. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

4. Run the file.

   ```text
   go run edit-index.go
   ```

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index using the [Go Driver:](https://www.mongodb.com/docs/drivers/go/current/)

1. Create a new file named `delete-index.go`.

2. Copy the following code example into the file.

   The following sample application deletes a MongoDB Search index on the specified collection.

   ```go
   package main

   import (
   	"context"
   	"log"

   	"go.mongodb.org/mongo-driver/v2/mongo"
   	"go.mongodb.org/mongo-driver/v2/mongo/options"
   )

   func main() {
   	ctx := context.Background()

   	// Replace the placeholder with your Atlas connection string
   	const uri = "<connection-string>"

   	// Connect to your Atlas cluster
   	clientOptions := options.Client().ApplyURI(uri)
   	client, err := mongo.Connect(clientOptions)
   	if err != nil {
   		log.Fatalf("failed to connect to the server: %v", err)
   	}
   	defer func() { _ = client.Disconnect(ctx) }()

   	// Set the namespace
   	coll := client.Database("<database-name>").Collection("<collection-name>")

   	// Specifies the index name of the index to delete
   	const indexName = "<index-name>"

   	// Deletes the specified index
   	err = coll.SearchIndexes().DropOne(ctx, indexName)
   	if err != nil {
   		log.Fatalf("Failed to delete the index: %v", err)
   	}
   }

   ```

3. Replace the following values and then save the file.

   - `<connection-string>`: Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - `<database-name>` and  `<collection-name>`: The names of the database and collection for which you want to retrieve the index.

   - `<index-name>`: The name of the index you want to delete.

4. Run the file.

   ```text
   go run delete-index.go
   ```

## Considerations for MongoDB Search Indexes

When creating and managing MongoDB Search indexes, consider the following:

### Index Consistency and Rebuilding

#### When is query data consistent after updates?

If you make changes to the collection for which you defined MongoDB Search indexes, the latest data might not be available immediately for queries. However, `mongot` monitors the change streams, which allows it to update stored copies of data, and MongoDB Search indexes are eventually consistent.

When you change an index definition, `mongot` automatically rebuilds the new index in the background, while continuing to serve queries with the old index to make sure there is no downtime. It is recommended that you wait for the index build to complete before running any queries using new index definitions. Using the new index during its build process can lead to unexpected results or incomplete data. This happens when you deploy `mongot` and `mongod` processes on the same node and when you deploy the processes on different nodes. Atlas also rebuilds indexes when you enable or disable [Encryption at Rest.](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption)

If you change the topology of your search deployment, MongoDB Search provisions and builds indexes on any new nodes before removing old nodes, to ensure there is no query downtime.

For deployments where both the `mongod` and `mongot` processes run on the same node, if MongoDB Search introduces changes that require rebuilding your indexes (such as some MongoDB Search features that require an [index update](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-fts-index-rebuild)), Atlas automatically deploys additional nodes for free to build the indexes, while the old nodes continue to serve your queries.

WARNING: If you shard a collection that already has a MongoDB Search index, you might experience a brief period of incomplete search results while the index is building on a shard. Also, if you add a shard for an already sharded collection that contains a MongoDB Search index, your search queries against that collection might return incomplete results until the initial sync process completes on the added shards. To learn more, see [initial sync process.](https://www.mongodb.com/docs/search/performance/index-performance.md#std-label-troubleshoot-initial-sync)

IMPORTANT: If you use the [$out](https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/) aggregation stage to modify a collection with an existing MongoDB Search index, you must delete and re-create the search index. If possible, consider using [$merge](https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/) instead of `$out`.

### Dedicated Search Nodes

#### How are MongoDB Search indexes affected by dedicated Search Node architecture?

You can deploy [dedicated Search Nodes](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-what-is-search-node) to improve performance, scalability, and resource isolation.

If you've deployed Search Nodes, consider the following:

- Adding and adjusting [shards](https://www.mongodb.com/docs/manual/sharding.md#std-label-sharding-background) triggers a rebuild of the MongoDB Search index. During this index rebuild, the index might not have the most current data. Therefore, queries against data on those shards might fail or return incorrect results.

- If you [reshard](https://www.mongodb.com/docs/manual/core/sharding-reshard-a-collection.md#std-label-sharding-resharding) a collection with MongoDB Search indexes, MongoDB Search indexes on the collection become unavailable when the resharding operation completes. You *must* manually rebuild the MongoDB Search indexes once the operation completes.

- If you issue the command to [change the primary shard](https://www.mongodb.com/docs/manual/reference/command/movePrimary/) of a database, the MongoDB Search indexes for any unsharded collection under this database become unavailable once the operation completes. You *must* delete and create new MongoDB Search indexes once the [`movePrimary`](https://www.mongodb.com/docs/manual/reference/command/movePrimary.md#mongodb-dbcommand-dbcmd.movePrimary) operation is complete.

- Scaling your cluster by adding search nodes or by changing the search tier triggers a rebuild of the full MongoDB Search index. However, if your cluster has dedicated search nodes for which you haven't enabled [Encryption at Rest using Customer Key Management](https://www.mongodb.com/docs/atlas/security-kms-encryption.md#std-label-security-kms-encryption), Atlas provides the following optimizations:

  - When you scale your search nodes, Atlas uses a recent copy of your index in S3 (Simple Storage Service), Google Cloud Storage, or Azure Blob Storage instead of rebuilding the entire MongoDB Search index on the new node.

  - For existing nodes, Atlas periodically takes and uploads a new incremental list of index files. Atlas retains index files for up to fourteen (14) days.

To learn more about MongoDB Search node architecture, see [MongoDB Search Deployment Options.](https://www.mongodb.com/docs/search/deployment/deployment-options.md#std-label-fts-deployment-options)

### Disk, Memory, and Resource Usage

#### How do MongoDB Search indexes affect your available disk space and memory?

Although the data stored on MongoDB Search isn't an identical copy of data from the collection on your Atlas cluster, MongoDB Search indexes still take some disk space and memory. If you enable the `store` option for fields that contain [string](https://www.mongodb.com/docs/search/indexes/field-types/string-type.md#std-label-bson-data-types-string) values or if you configure the [stored source fields](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition) in your index, MongoDB Search stores an identical copy of the specified fields on disk, which can take disk space.

**Important:**

If your collection contains documents that are 16MB (BSON (Binary Javascript Object Notation) limit), MongoDB Search fails to index the document, causes your index to become [STALE](https://www.mongodb.com/docs/search/indexes/manage-indexes.md#std-label-index-statuses), and requires a full index rebuild. This issue can also occur when update operations on documents cause the change stream event to exceed the 16MB BSON (Binary Javascript Object Notation) limit. To minimize the risk of your index becoming stale, ensure that documents in your collection don't exceed 8MB. If your index has become stale, you must delete the large document(s) from your collection in order for the index rebuild to complete.

In addition:

- Structure your documents to minimize the size of sub-documents or arrays.

- Avoid operations that update or replace large fields, sub-documents, or arrays.

To learn more, see [Change Streams Production Recommendations](https://www.mongodb.com/docs/manual/administration/change-streams-production-recommendations/) and [Reduce the Size of Large Documents.](https://www.mongodb.com/docs/ops-manager/current/schema-advisor/reduce-document-size/)

### Concurrent Requests Error

#### What happens if there are too many concurrent MongoDB Search index management requests?

If there are too many concurrent index creation or other index management operation requests, MongoDB Search returns the following error:

```shell
Too many concurrent requests. Please try again later.
```

We recommend trying again after some time.

## Create a MongoDB Search Index

To create a MongoDB Search index through the [Go Driver:](https://www.mongodb.com/docs/drivers/go/current/)

1. Define the search index from your application.

2. Run the `createOne()` helper method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the search indexes, call the `SearchIndexes().List()` method on your collection.

1. Create a new file named `create-index.go`.

2. Copy the following code example into the file.

   The following sample application creates a MongoDB Search index on a collection.

   ```go
   package main

   import (
   	"context"
   	"log"

   	"go.mongodb.org/mongo-driver/v2/bson"
   	"go.mongodb.org/mongo-driver/v2/mongo"
   	"go.mongodb.org/mongo-driver/v2/mongo/options"
   )

   func main() {
   	ctx := context.Background()

   	// Replace the placeholder with your Atlas connection string
   	const uri = "<connection-string>"

   	// Connect to your Atlas cluster
   	clientOptions := options.Client().ApplyURI(uri)
   	client, err := mongo.Connect(clientOptions)
   	if err != nil {
   		log.Fatalf("failed to connect to the server: %v", err)
   	}
   	defer func() { _ = client.Disconnect(ctx) }()

   	// Set the namespace
   	coll := client.Database("<database-name>").Collection("<collection-name>")

   	// Define a simple MongoDB Search index
   	indexName := "<index-name>"

   	// Create the default definition for search index
   	definition := bson.D{{"mappings", bson.D{{"dynamic", true}}}}
   	indexModel := mongo.SearchIndexModel{
   		Definition: definition,
   		Options:    options.SearchIndexes().SetName(indexName),
   	}

   	// Create the index
   	searchIndexName, err := coll.SearchIndexes().CreateOne(ctx, indexModel)
   	if err != nil {
   		log.Fatalf("failed to create the search index: %v", err)
   	}
   	log.Println("New search index named " + searchIndexName + " is building.")
   }

   ```

3. Replace the following values and then save the file.

   - `<connection-string>`: Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - `<database-name>` and  `<collection-name>`: The names of the database and collection for which you want to retrieve the index.

   - `<index-name>`: The name of your index. If you omit the index name, MongoDB Search names the index `default`.

4. Run the file.

   ```text
   go run create-index.go
   ```

## View MongoDB Search Indexes

To use the [Go Driver](https://www.mongodb.com/docs/drivers/go/current/) to retrieve a MongoDB Search index by specifying the index name:

1. Create a new file named `view-index.go`.

2. Copy the following code example into the file.

   The following sample application retrieves a MongoDB Search index by name from the specified collection.

   ```go
   package main

   import (
   	"context"
   	"encoding/json"
   	"fmt"
   	"log"

   	"go.mongodb.org/mongo-driver/v2/bson"
   	"go.mongodb.org/mongo-driver/v2/mongo"
   	"go.mongodb.org/mongo-driver/v2/mongo/options"
   )

   func main() {
   	ctx := context.Background()

   	// Replace the placeholder with your Atlas connection string
   	const uri = "<connection-string>"

   	// Connect to your Atlas cluster
   	clientOptions := options.Client().ApplyURI(uri)
   	client, err := mongo.Connect(clientOptions)
   	if err != nil {
   		log.Fatalf("failed to connect to the server: %v", err)
   	}
   	defer func() { _ = client.Disconnect(ctx) }()

   	// Set the namespace
   	coll := client.Database("<database-name>").Collection("<collection-name>")

   	// Specifies the index to retrieve
   	const indexName = "<index-name>"
   	opts := options.SearchIndexes().SetName(indexName)

   	// Retrieves the details of the specified index
   	cursor, err := coll.SearchIndexes().List(ctx, opts)
   	if err != nil {
   		log.Fatalf("failed to retrieve search index: %v", err)
   	}

   	// Prints the index details to the console as JSON
   	var results []bson.D
   	if err := cursor.All(ctx, &results); err != nil {
   		log.Fatalf("failed to unmarshal results to bson: %v", err)
   	}
   	jsonResults, err := json.Marshal(results)
   	if err != nil {
   		log.Fatalf("failed to marshal results to json: %v", err)
   	}
   	fmt.Println(string(jsonResults))
   }

   ```

3. Replace the following values and then save the file.

   - `<collection-name>` - The name of the collection for which you want to retrieve the index.

   - `<database-name>` and  `<collection-name>`: The names of the database and collection for which you want to retrieve the index.

   - `<index-name>`: The name of the index you want to retrieve.

4. Run the file.

   ```shell
   go run view-index.go
   ```

## Edit a MongoDB Search Index

To edit a MongoDB Search index using the [Go Driver:](https://www.mongodb.com/docs/drivers/go/current/)

1. Create a new file named `edit-index.go`.

2. Copy the following code example into the file.

   The following sample application edits a MongoDB Search index on the specified collection.

   ```go
   package main

   import (
   	"context"
   	"log"

   	"go.mongodb.org/mongo-driver/v2/bson"
   	"go.mongodb.org/mongo-driver/v2/mongo"
   	"go.mongodb.org/mongo-driver/v2/mongo/options"
   )

   func main() {
   	ctx := context.Background()

   	// Replace the placeholder with your Atlas connection string
   	const uri = "<connection-string>"

   	// Connect to your Atlas cluster
   	clientOptions := options.Client().ApplyURI(uri)
   	client, err := mongo.Connect(clientOptions)
   	if err != nil {
   		log.Fatalf("failed to connect to the server: %v", err)
   	}
   	defer func() { _ = client.Disconnect(ctx) }()

   	// Set the namespace
   	coll := client.Database("<database-name>").Collection("<collection-name>")

   	// Specifies the index name and the new index definition
   	const indexName = "<index-name>"

   	// Define the new index definition
   	definition := bson.D{<index-definition>}

   	// Updates the specified index
   	err = coll.SearchIndexes().UpdateOne(ctx, indexName, definition)
   	if err != nil {
   		log.Fatalf("Failed to update the index: %v", err)
   	}
   }

   ```

3. Replace the following values and then save the file.

   - `<connection-string>`: Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - `<database-name>` and  `<collection-name>`: The names of the database and collection for which you want to retrieve the index.

   - `<index-name>`: The name of the index you want to edit.

   - `<index-definition>`: The new search index definition. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

4. Run the file.

   ```text
   go run edit-index.go
   ```

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index using the [Go Driver:](https://www.mongodb.com/docs/drivers/go/current/)

1. Create a new file named `delete-index.go`.

2. Copy the following code example into the file.

   The following sample application deletes a MongoDB Search index on the specified collection.

   ```go
   package main

   import (
   	"context"
   	"log"

   	"go.mongodb.org/mongo-driver/v2/mongo"
   	"go.mongodb.org/mongo-driver/v2/mongo/options"
   )

   func main() {
   	ctx := context.Background()

   	// Replace the placeholder with your Atlas connection string
   	const uri = "<connection-string>"

   	// Connect to your Atlas cluster
   	clientOptions := options.Client().ApplyURI(uri)
   	client, err := mongo.Connect(clientOptions)
   	if err != nil {
   		log.Fatalf("failed to connect to the server: %v", err)
   	}
   	defer func() { _ = client.Disconnect(ctx) }()

   	// Set the namespace
   	coll := client.Database("<database-name>").Collection("<collection-name>")

   	// Specifies the index name of the index to delete
   	const indexName = "<index-name>"

   	// Deletes the specified index
   	err = coll.SearchIndexes().DropOne(ctx, indexName)
   	if err != nil {
   		log.Fatalf("Failed to delete the index: %v", err)
   	}
   }

   ```

3. Replace the following values and then save the file.

   - `<connection-string>`: Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - `<database-name>` and  `<collection-name>`: The names of the database and collection for which you want to retrieve the index.

   - `<index-name>`: The name of the index you want to delete.

4. Run the file.

   ```text
   go run delete-index.go
   ```

## Create a MongoDB Search Index

To create a MongoDB Search index through the [Go Driver:](https://www.mongodb.com/docs/drivers/go/current/)

1. Define the search index from your application.

2. Run the `createOne()` helper method.

**Note:**

The MongoDB Search index management methods run asynchronously. The driver methods can return before confirming that they ran successfully. To determine the current status of the search indexes, call the `SearchIndexes().List()` method on your collection.

1. Create a new file named `create-index.go`.

2. Copy the following code example into the file.

   The following sample application creates a MongoDB Search index on a collection.

   ```go
   package main

   import (
   	"context"
   	"log"

   	"go.mongodb.org/mongo-driver/v2/bson"
   	"go.mongodb.org/mongo-driver/v2/mongo"
   	"go.mongodb.org/mongo-driver/v2/mongo/options"
   )

   func main() {
   	ctx := context.Background()

   	// Replace the placeholder with your Atlas connection string
   	const uri = "<connection-string>"

   	// Connect to your Atlas cluster
   	clientOptions := options.Client().ApplyURI(uri)
   	client, err := mongo.Connect(clientOptions)
   	if err != nil {
   		log.Fatalf("failed to connect to the server: %v", err)
   	}
   	defer func() { _ = client.Disconnect(ctx) }()

   	// Set the namespace
   	coll := client.Database("<database-name>").Collection("<collection-name>")

   	// Define a simple MongoDB Search index
   	indexName := "<index-name>"

   	// Create the default definition for search index
   	definition := bson.D{{"mappings", bson.D{{"dynamic", true}}}}
   	indexModel := mongo.SearchIndexModel{
   		Definition: definition,
   		Options:    options.SearchIndexes().SetName(indexName),
   	}

   	// Create the index
   	searchIndexName, err := coll.SearchIndexes().CreateOne(ctx, indexModel)
   	if err != nil {
   		log.Fatalf("failed to create the search index: %v", err)
   	}
   	log.Println("New search index named " + searchIndexName + " is building.")
   }

   ```

3. Replace the following values and then save the file.

   - `<connection-string>`: Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - `<database-name>` and  `<collection-name>`: The names of the database and collection for which you want to retrieve the index.

   - `<index-name>`: The name of your index. If you omit the index name, MongoDB Search names the index `default`.

4. Run the file.

   ```text
   go run create-index.go
   ```

## View MongoDB Search Indexes

To use the [Go Driver](https://www.mongodb.com/docs/drivers/go/current/) to retrieve a MongoDB Search index by specifying the index name:

1. Create a new file named `view-index.go`.

2. Copy the following code example into the file.

   The following sample application retrieves a MongoDB Search index by name from the specified collection.

   ```go
   package main

   import (
   	"context"
   	"encoding/json"
   	"fmt"
   	"log"

   	"go.mongodb.org/mongo-driver/v2/bson"
   	"go.mongodb.org/mongo-driver/v2/mongo"
   	"go.mongodb.org/mongo-driver/v2/mongo/options"
   )

   func main() {
   	ctx := context.Background()

   	// Replace the placeholder with your Atlas connection string
   	const uri = "<connection-string>"

   	// Connect to your Atlas cluster
   	clientOptions := options.Client().ApplyURI(uri)
   	client, err := mongo.Connect(clientOptions)
   	if err != nil {
   		log.Fatalf("failed to connect to the server: %v", err)
   	}
   	defer func() { _ = client.Disconnect(ctx) }()

   	// Set the namespace
   	coll := client.Database("<database-name>").Collection("<collection-name>")

   	// Specifies the index to retrieve
   	const indexName = "<index-name>"
   	opts := options.SearchIndexes().SetName(indexName)

   	// Retrieves the details of the specified index
   	cursor, err := coll.SearchIndexes().List(ctx, opts)
   	if err != nil {
   		log.Fatalf("failed to retrieve search index: %v", err)
   	}

   	// Prints the index details to the console as JSON
   	var results []bson.D
   	if err := cursor.All(ctx, &results); err != nil {
   		log.Fatalf("failed to unmarshal results to bson: %v", err)
   	}
   	jsonResults, err := json.Marshal(results)
   	if err != nil {
   		log.Fatalf("failed to marshal results to json: %v", err)
   	}
   	fmt.Println(string(jsonResults))
   }

   ```

3. Replace the following values and then save the file.

   - `<collection-name>` - The name of the collection for which you want to retrieve the index.

   - `<database-name>` and  `<collection-name>`: The names of the database and collection for which you want to retrieve the index.

   - `<index-name>`: The name of the index you want to retrieve.

4. Run the file.

   ```shell
   go run view-index.go
   ```

## Edit a MongoDB Search Index

To edit a MongoDB Search index using the [Go Driver:](https://www.mongodb.com/docs/drivers/go/current/)

1. Create a new file named `edit-index.go`.

2. Copy the following code example into the file.

   The following sample application edits a MongoDB Search index on the specified collection.

   ```go
   package main

   import (
   	"context"
   	"log"

   	"go.mongodb.org/mongo-driver/v2/bson"
   	"go.mongodb.org/mongo-driver/v2/mongo"
   	"go.mongodb.org/mongo-driver/v2/mongo/options"
   )

   func main() {
   	ctx := context.Background()

   	// Replace the placeholder with your Atlas connection string
   	const uri = "<connection-string>"

   	// Connect to your Atlas cluster
   	clientOptions := options.Client().ApplyURI(uri)
   	client, err := mongo.Connect(clientOptions)
   	if err != nil {
   		log.Fatalf("failed to connect to the server: %v", err)
   	}
   	defer func() { _ = client.Disconnect(ctx) }()

   	// Set the namespace
   	coll := client.Database("<database-name>").Collection("<collection-name>")

   	// Specifies the index name and the new index definition
   	const indexName = "<index-name>"

   	// Define the new index definition
   	definition := bson.D{<index-definition>}

   	// Updates the specified index
   	err = coll.SearchIndexes().UpdateOne(ctx, indexName, definition)
   	if err != nil {
   		log.Fatalf("Failed to update the index: %v", err)
   	}
   }

   ```

3. Replace the following values and then save the file.

   - `<connection-string>`: Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - `<database-name>` and  `<collection-name>`: The names of the database and collection for which you want to retrieve the index.

   - `<index-name>`: The name of the index you want to edit.

   - `<index-definition>`: The new search index definition. To learn more, see [Index Reference.](https://www.mongodb.com/docs/search/indexes/index-definitions.md#std-label-ref-index-definitions)

4. Run the file.

   ```text
   go run edit-index.go
   ```

**Note:**

While your updated index is building, different nodes might update at varying speeds. During this period, you might experience mixed query results, reflecting both the new index definition and the previous index definition.

## Delete a MongoDB Search Index

**Warning: Deleting Search Indexes and Clusters Is Irreversible**

Deleting Search indexes and associated clusters is a permanent action. MongoDB doesn't provide support for recovering deleted Search indexes or data. Ensure that you have taken appropriate measures, such as creating backups, to avoid data loss before proceeding.

MongoDB doesn't support requests to recover deleted Search indexes or data. You are responsible for data integrity and configurations.

To delete a MongoDB Search index using the [Go Driver:](https://www.mongodb.com/docs/drivers/go/current/)

1. Create a new file named `delete-index.go`.

2. Copy the following code example into the file.

   The following sample application deletes a MongoDB Search index on the specified collection.

   ```go
   package main

   import (
   	"context"
   	"log"

   	"go.mongodb.org/mongo-driver/v2/mongo"
   	"go.mongodb.org/mongo-driver/v2/mongo/options"
   )

   func main() {
   	ctx := context.Background()

   	// Replace the placeholder with your Atlas connection string
   	const uri = "<connection-string>"

   	// Connect to your Atlas cluster
   	clientOptions := options.Client().ApplyURI(uri)
   	client, err := mongo.Connect(clientOptions)
   	if err != nil {
   		log.Fatalf("failed to connect to the server: %v", err)
   	}
   	defer func() { _ = client.Disconnect(ctx) }()

   	// Set the namespace
   	coll := client.Database("<database-name>").Collection("<collection-name>")

   	// Specifies the index name of the index to delete
   	const indexName = "<index-name>"

   	// Deletes the specified index
   	err = coll.SearchIndexes().DropOne(ctx, indexName)
   	if err != nil {
   		log.Fatalf("Failed to delete the index: %v", err)
   	}
   }

   ```

3. Replace the following values and then save the file.

   - `<connection-string>`: Your Atlas connection string. To learn more, see [Connect to a Cluster via Client Libraries.](https://www.mongodb.com/docs/atlas/driver-connection.md#std-label-connect-via-driver)

   - `<database-name>` and  `<collection-name>`: The names of the database and collection for which you want to retrieve the index.

   - `<index-name>`: The name of the index you want to delete.

4. Run the file.

   ```text
   go run delete-index.go
   ```

## Learn More

- To learn how to define a MongoDB Search index to meet your MongoDB Search query needs, see [Define Your Query.](https://www.mongodb.com/docs/search/about/searching.md#std-label-atlas-search-queries)

- To learn how to create a MongoDB Search index, see [Create a MongoDB Search index.](https://www.mongodb.com/docs/search/tutorial.md#std-label-create-fts-index)

- To learn more about the MongoDB Search index configurations described in this tutorial, see the following reference pages:

  - [Process Data with Analyzers](https://www.mongodb.com/docs/search/indexes/analyzers/overview.md#std-label-analyzers-ref)

  - [Define Field Mappings for a MongoDB Search Index](https://www.mongodb.com/docs/search/indexes/define-field-mappings.md#std-label-fts-field-mappings)

  - [Define Stored Source Fields in Your MongoDB Search Index](https://www.mongodb.com/docs/search/indexes/stored-source-definition.md#std-label-fts-stored-source-definition)

  - [Define Synonym Mappings in Your MongoDB Search Index](https://www.mongodb.com/docs/search/indexes/synonyms.md#std-label-synonyms-ref)

- For hands-on experience creating MongoDB Search indexes for the [sample datasets](https://www.mongodb.com/docs/manual/sample-data.md#std-label-available-sample-datasets) and running MongoDB Search queries against the indexed data, try the [MongoDB Search Quick Start.](https://www.mongodb.com/docs/search/tutorial.md#std-label-fts-tutorial-ref)

- For a conceptual overview of how to define an index to meet your query preferences, see [Define Your Index.](https://www.mongodb.com/docs/search/about/searching.md#std-label-fts-define-index)

- To retrieve MongoDB Search index size and other search metrics programmatically using the Atlas Administration API, see [Retrieve MongoDB Search Metrics Programmatically.](https://www.mongodb.com/docs/atlas/review-atlas-search-metrics.md#std-label-fts-metrics-programmatic-retrieval)

### Learn by Watching

You can also watch the following videos to learn more about MongoDB Search indexes:

#### Video: An Introduction to Indexes for MongoDB Search

##### Watch an overview of MongoDB Search Indexes.

Follow along with this video tutorial walk-through that demonstrates how to create MongoDB Search indexes of various complexity.

*Duration: 15 Minutes*
