Delete an Atlas Search Index
On this page
Required Access
The following table shows the modes of access each role supports.
Role | Action | Atlas UI | Atlas API | Atlas Search API | Atlas CLI |
---|---|---|---|---|---|
Project Data Access Read Only or higher role | To view Atlas Search analyzers and indexes. | ✓ | ✓ | ||
Project Data Access Admin or higher role | To create and manage Atlas Search analyzers and indexes, and
assign the role to your API Key. | ✓ | ✓ | ✓ | ✓ |
Project Owner role | ✓ | ✓ | |||
Organization Owner role | To create access list entries for your API
Key and send the request from a client that appears in the
access list for your API Key. | ✓ | ✓ | ||
To create, view, edit, and delete Atlas Search indexes using the
Atlas UI or API. | ✓ | ✓ | ✓ |
Delete an Atlas Search Index
You can delete an Atlas Search index in the Atlas UI, or programmatically by
using mongosh
, the Atlas CLI, the API, or a supported
MongoDB Driver in your preferred language.
Note
You must have at least the
readWriteAnyDatabase
role or readWrite
access to
the database that contains the indexes. To learn more,
see Built-in Roles or Specific Privileges.
➤ Use the Select your language drop-down menu to set the language of the example in this section.
To delete an Atlas Search index through the API:
Send a DELETE
request.
Send a DELETE
request with either the unique ID or name
of the Atlas Search index that you wish to delete to the search/indexes/
endpoint.
curl --user "{PUBLIC-KEY}:{PRIVATE-KEY}" --digest \ --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 and Delete One By ID.
Delete an Atlas Search Index for a Cloud Deployment
To delete a search index from a cluster using the Atlas CLI, run the following command:
atlas clusters search indexes delete <indexId> [options]
To learn more about the command syntax and parameters, see the Atlas CLI documentation for atlas clusters search indexes delete.
Tip
See: Related Links
Delete an Atlas Search Index for a Local Deployment
To delete the specified search index for the specified deployment using the Atlas CLI, run the following command:
atlas deployments search indexes delete <indexId> [options]
To learn more about the command syntax and parameters, see the Atlas CLI documentation for atlas deployments search indexes delete.
Tip
See: Related Links
In Atlas, go to the Clusters page for your project.
If it is not already displayed, select the organization that contains your desired project from the Organizations menu in the navigation bar.
If it is not already displayed, select your desired project from the Projects menu in the navigation bar.
If the Clusters page is not already displayed, click Database in the sidebar.
Go to the Atlas Search page for your cluster.
You can go the Atlas Search page from the sidebar, the Data Explorer, or your cluster details page.
In the sidebar, click Atlas Search under the Services heading.
From the Select data source dropdown, select your cluster and click Go to Atlas Search.
Click the Browse Collections button for your cluster.
Expand the database and select the collection.
Click the Search Indexes tab for the collection.
Click the cluster's name.
Click the Atlas Search tab.
To delete an Atlas Search index through mongosh
, use
the db.collection.dropSearchIndex()
method.
The command has the following syntax:
db.<collection>.dropSearchIndex("<index-name>")
Example
The following command deletes a search
index named default
from the movies
collection:
db.movies.dropSearchIndex("default")
Note
The db.collection.dropSearchIndex()
command doesn't
return an output. You can use the Atlas UI to
view the index status.
To use the C Driver to delete your Atlas Search index, pass
your collection and the drop command to the mongoc_collection_command_simple()
method.
Example
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 and passes this information to
the mongoc_collection_command_simple()
method to delete the search index.
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; }
Specify the following values and save the file.
Your Atlas connection string. To learn more, see Connect via Drivers.
The database and collection for which you want to delete an index.
The name of the index that you want to delete.
To use the C++ Driver to delete your Atlas Search index, call
the drop_one()
method on a search index view.
Example
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
an Atlas Search index name as a parameter to delete the index.
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; }
Specify the following values and save the file.
Your Atlas connection string. To learn more, see Connect via Drivers.
The database and collection for which you want to retrieve the indexes.
The name of the index that you want to delete.
To use the .NET/C# Driver to delete an Atlas 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 via Drivers.
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.
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 Atlas 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:
dotnet run csharp-delete-index.csproj
Note
The DropOne()
method doesn't return an output.
You can use the Atlas UI to view the
index status.
Tip
API Documentation
To learn more about the methods on this page, see the API documentation for the .NET/C# driver.
To delete an Atlas Search index on a collection using the Java
Driver,
use the dropSearchIndex()
method. You must have Java
Driver v4.11.0 or higher.
Copy the following code example into the file.
The following sample application deletes the specified Atlas Search index on the specified collection.
1 import com.mongodb.client.MongoClient; 2 import com.mongodb.client.MongoClients; 3 import com.mongodb.client.MongoCollection; 4 import com.mongodb.client.MongoDatabase; 5 import org.bson.Document; 6 7 public class DeleteIndex { 8 public static void main(String[] args) { 9 // connect to your Atlas cluster 10 String uri = "<connection-string>"; 11 12 try (MongoClient mongoClient = MongoClients.create(uri)) { 13 // set namespace 14 MongoDatabase database = mongoClient.getDatabase("<database-name>"); 15 MongoCollection<Document> collection = database.getCollection("<collection>"); 16 // delete the index 17 collection.dropSearchIndex("<index-name>"); 18 } 19 } 20 }
Replace the following values and then save the file.
<connection-string>
- Your Atlas connection string. To learn more, see Connect via Drivers.Note
In your connection string, don't include the writeConcern 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.
Tip
See also:
To delete an Atlas Search index through the Node Driver,
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 via Drivers.
The database and collection where you created the search index.
The name of the index that you want to delete.
// 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.
node drop-index.js
Note
The dropSearchIndex
method doesn't return an output.
You can use the Atlas UI to view the
index status.
To use the Python Driver to delete your Atlas Search
index, call the drop_search_index()
method on your collection.
Example
Copy the following code example into the file.
The following sample application passes an Atlas Search index name to
the drop_search_index()
method to delete the index.
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>")
Specify the following values and save the file.
Your Atlas connection string. To learn more, see Connect via Drivers.
The database and collection for which you want to delete an index.
The name of the index that you want to delete.