mongodb_delete_collection
Delete a MongoDB collection from a specified database to remove unwanted data or clean up storage space.
Instructions
Удаляет коллекцию из базы данных
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| databaseName | Yes | Имя базы данных | |
| collectionName | Yes | Имя коллекции для удаления |
Implementation Reference
- src/index.ts:724-747 (handler)TypeScript handler function that connects to MongoDB, drops the specified collection, and returns a success or error message.private async mongodbDeleteCollection( databaseName: string, collectionName: string ) { const client = await this.getMongoClient(); try { const db = client.db(databaseName); await db.collection(collectionName).drop(); return { content: [ { type: "text", text: `Коллекция "${collectionName}" успешно удалена из базы данных "${databaseName}"`, }, ], }; } catch (error) { throw new Error( `Ошибка удаления коллекции: ${error instanceof Error ? error.message : String(error)}` ); } finally { await client.close(); } }
- src/server.py:483-496 (handler)Python handler function that connects to MongoDB using PyMongo, drops the specified collection, and returns a success or error message.def mongodb_delete_collection(database_name: str, collection_name: str) -> str: """Deletes collection""" client = MongoClient(MONGODB_URI) try: db = client[database_name] db[collection_name].drop() return ( f'Collection "{collection_name}" successfully deleted ' f'from database "{database_name}"' ) except Exception as e: raise Exception(f"Error deleting collection: {str(e)}") finally: client.close()
- src/index.ts:212-227 (schema)Input schema definition for the mongodb_delete_collection tool in the TypeScript MCP server.name: "mongodb_delete_collection", description: "Удаляет коллекцию из базы данных", inputSchema: { type: "object", properties: { databaseName: { type: "string", description: "Имя базы данных", }, collectionName: { type: "string", description: "Имя коллекции для удаления", }, }, required: ["databaseName", "collectionName"], },
- src/server.py:199-214 (schema)Input schema definition for the mongodb_delete_collection tool in the Python MCP server."name": "mongodb_delete_collection", "description": "Deletes collection from database", "inputSchema": { "type": "object", "properties": { "databaseName": { "type": "string", "description": "Database name", }, "collectionName": { "type": "string", "description": "Collection name to delete", }, }, "required": ["databaseName", "collectionName"], },
- src/index.ts:353-357 (registration)Dispatch/registration case in the TypeScript tools/call handler that invokes the mongodbDeleteCollection method.case "mongodb_delete_collection": return await this.mongodbDeleteCollection( args?.databaseName as string, args?.collectionName as string );