Skip to main content
Glama
manpreet2000

MCP Database Server

deleteOne

Remove a single document from a MongoDB collection using a specific query filter to delete targeted data.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionNameYes
queryYes

Implementation Reference

  • Handler function that connects to MongoDB if necessary, retrieves the collection, executes deleteOne with the provided query, and returns success or error message.
    async ({ collectionName, query }) => { try { let db = mongodbConnection.getDb(); if (!db) { await mongodbConnection.connect(this.MONGODB_URI); db = mongodbConnection.getDb(); if (!db) throw new Error("Failed to connect to database"); } const collection = db.collection(collectionName); await collection.deleteOne(query); return { content: [{ type: "text", text: "Document deleted successfully" }], }; } catch (error) { console.error(error); return { content: [{ type: "text", text: "Error: " + error }], }; } }
  • Zod schema defining input parameters for deleteOne tool: collectionName (string) and query (object).
    { collectionName: z.string(), query: z.object({}), },
  • src/index.ts:124-150 (registration)
    Registration of the deleteOne tool with the MCP server using this.mcpServer.tool(name, schema, handler).
    this.mcpServer.tool( "deleteOne", { collectionName: z.string(), query: z.object({}), }, async ({ collectionName, query }) => { try { let db = mongodbConnection.getDb(); if (!db) { await mongodbConnection.connect(this.MONGODB_URI); db = mongodbConnection.getDb(); if (!db) throw new Error("Failed to connect to database"); } const collection = db.collection(collectionName); await collection.deleteOne(query); return { content: [{ type: "text", text: "Document deleted successfully" }], }; } catch (error) { console.error(error); return { content: [{ type: "text", text: "Error: " + error }], }; } } );

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/manpreet2000/mcp-database-server'

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