Skip to main content
Glama

mongodb_delete_document

Remove documents from a MongoDB collection using a JSON filter. Specify database, collection, and filter criteria to delete matching records.

Instructions

Удаляет документ(ы) из коллекции по фильтру

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseNameYesИмя базы данных
collectionNameYesИмя коллекции
filterYesJSON строка с фильтром для удаления

Implementation Reference

  • The handler function for 'mongodb_delete_document' tool. Connects to MongoDB using getMongoClient, parses the filter JSON, executes deleteMany on the specified collection, returns content with the number of deleted documents.
    private async mongodbDeleteDocument( databaseName: string, collectionName: string, filterJson: string ) { const client = await this.getMongoClient(); try { const db = client.db(databaseName); const collection = db.collection(collectionName); const filter = JSON.parse(filterJson); const result = await collection.deleteMany(filter); return { content: [ { type: "text", text: `Удалено документов: ${result.deletedCount}`, }, ], }; } catch (error) { throw new Error( `Ошибка удаления документа: ${error instanceof Error ? error.message : String(error)}` ); } finally { await client.close(); } }
  • Input schema definition for the 'mongodb_delete_document' tool in the list of tools returned by ListToolsRequestHandler.
    { name: "mongodb_delete_document", description: "Удаляет документ(ы) из коллекции по фильтру", inputSchema: { type: "object", properties: { databaseName: { type: "string", description: "Имя базы данных", }, collectionName: { type: "string", description: "Имя коллекции", }, filter: { type: "string", description: "JSON строка с фильтром для удаления", }, }, required: ["databaseName", "collectionName", "filter"], }, },
  • src/index.ts:374-379 (registration)
    Registration/dispatch in the CallToolRequestHandler switch statement that invokes the mongodbDeleteDocument handler.
    case "mongodb_delete_document": return await this.mongodbDeleteDocument( args?.databaseName as string, args?.collectionName as string, args?.filter as string );
  • Python implementation of the mongodb_delete_document handler function. Parses filter JSON, performs delete_many, returns deleted count. Note: dispatch is commented out in handle_request.
    def mongodb_delete_document( database_name: str, collection_name: str, filter_json: str ) -> str: """Deletes document(s) by filter""" client = MongoClient(MONGODB_URI) try: db = client[database_name] collection = db[collection_name] filter_dict = json.loads(filter_json) result = collection.delete_many(filter_dict) return f"Deleted documents: {result.deleted_count}" except Exception as e: raise Exception(f"Error deleting document: {str(e)}") finally: client.close()
  • Input schema for 'mongodb_delete_document' in the Python get_tools() function.
    { "name": "mongodb_delete_document", "description": "Deletes document(s) from collection by filter", "inputSchema": { "type": "object", "properties": { "databaseName": { "type": "string", "description": "Database name", }, "collectionName": { "type": "string", "description": "Collection name", }, "filter": { "type": "string", "description": "JSON string with deletion filter", }, }, "required": ["databaseName", "collectionName", "filter"], }, },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TrueOleg/MCP-expirements'

If you have feedback or need assistance with the MCP directory API, please join our Discord server