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 that executes the mongodb_delete_document tool. Connects to MongoDB, parses the filter JSON, performs deleteMany on the collection, and returns the count 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(); } }
  • The input schema definition for the mongodb_delete_document tool, specifying required parameters: databaseName, collectionName, and filter (JSON string).
    { 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)
    The switch case in the CallToolRequest handler that routes calls to the mongodbDeleteDocument method.
    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 tool handler (note: dispatch call 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()
  • The input schema definition for the mongodb_delete_document tool in the Python server.
    { "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