Docs Menu
Docs Home
/
MongoDB Atlas
/ /

Delete an Atlas Search Index

On this page

  • Required Access
  • Delete an Atlas Search Index

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.
✓
✓
To create and manage Atlas Search analyzers and indexes, and assign the role to your API Key.
✓
✓
✓
✓
✓
✓
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.
✓
✓
✓

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 can use the mongosh command or driver helper methods to delete Atlas Search indexes on all Atlas cluster tiers.

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:

1

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.

2

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

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.

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

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

  3. If the Clusters page is not already displayed, click Database in the sidebar.

    The Clusters page displays.

2

You can go the Atlas Search page from the sidebar, the Data Explorer, or your cluster details page.

  1. In the sidebar, click Atlas Search under the Services heading.

  2. From the Select data source dropdown, select your cluster and click Go to Atlas Search.

    The Atlas Search page displays.

  1. Click the Browse Collections button for your cluster.

  2. Expand the database and select the collection.

  3. Click the Search Indexes tab for the collection.

    The Atlas Search page displays.

  1. Click the cluster's name.

  2. Click the Atlas Search tab.

    The Atlas Search page displays.

3

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

4

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>")

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.

1
2

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.

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

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

To use the C++ Driver to delete your Atlas Search index, call the drop_one() method on a search index view.

1
2

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.

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

4
g++ -o delete-index delete-index.cpp $(pkg-config --cflags --libs libmongocxx)
./delete-index

To use the .NET/C# Driver to delete an Atlas Search index, use the DropOne() or DropOneAsync() method.

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.

Program.cs
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.

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.

1
2

The following sample application deletes the specified Atlas Search index on the specified collection.

1import com.mongodb.client.MongoClient;
2import com.mongodb.client.MongoClients;
3import com.mongodb.client.MongoCollection;
4import com.mongodb.client.MongoDatabase;
5import org.bson.Document;
6
7public 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}
3
  • <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.

4
javac DeleteIndex.java
java DeleteIndex

To delete an Atlas Search index through the Node Driver, use the dropSearchIndex helper method.

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.

drop-index.js
// 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.

1
2

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>")
3
  • 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.

4
python delete-index.py

Back

Edit