mongodb_delete
Delete documents from a MongoDB collection using query filters to remove specific data entries through the MCP-MongoDB-MySQL-Server interface.
Instructions
Delete documents from a MongoDB collection
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Collection name | |
| filter | Yes | MongoDB query filter | |
| many | No | Delete multiple documents if true |
Implementation Reference
- src/index.ts:1069-1100 (handler)The handler function that executes the mongodb_delete tool. It ensures MongoDB connection, validates inputs, and performs deleteOne or deleteMany based on the 'many' parameter.private async handleMongoDBDelete(args: any) { await this.ensureMongoConnection(); if (!args.collection || !args.filter) { throw new McpError(ErrorCode.InvalidParams, 'Collection name and filter are required'); } try { const collection = this.mongoDB!.collection(args.collection); let result; if (args.many) { result = await collection.deleteMany(args.filter); } else { result = await collection.deleteOne(args.filter); } return { content: [ { type: 'text', text: `Successfully deleted ${result.deletedCount} documents`, }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to delete documents: ${getErrorMessage(error)}` ); } }
- src/index.ts:490-512 (schema)The input schema definition for the mongodb_delete tool, specifying required collection and filter, optional many flag.{ name: 'mongodb_delete', description: 'Delete documents from a MongoDB collection', inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Collection name', }, filter: { type: 'object', description: 'MongoDB query filter', }, many: { type: 'boolean', description: 'Delete multiple documents if true', optional: true } }, required: ['collection', 'filter'], }, },
- src/index.ts:562-563 (registration)The switch case in the request handler that registers and dispatches calls to the mongodb_delete tool to its handler.case 'mongodb_delete': return await this.handleMongoDBDelete(request.params.arguments);