mongodb_insert_document
Insert JSON documents into MongoDB collections from macOS applications. Specify database, collection, and document data to add records to your database.
Instructions
Вставляет документ в коллекцию
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| databaseName | Yes | Имя базы данных | |
| collectionName | Yes | Имя коллекции | |
| document | Yes | JSON строка с документом для вставки |
Implementation Reference
- src/server.py:499-513 (handler)Python implementation of the mongodb_insert_document tool handler using pymongo to insert a single document into a MongoDB collection.def mongodb_insert_document( database_name: str, collection_name: str, document_json: str ) -> str: """Inserts document into collection""" client = MongoClient(MONGODB_URI) try: db = client[database_name] collection = db[collection_name] document = json.loads(document_json) result = collection.insert_one(document) return f'Document successfully inserted into collection "{collection_name}". ID: {result.inserted_id}' except Exception as e: raise Exception(f"Error inserting document: {str(e)}") finally: client.close()
- src/index.ts:749-776 (handler)TypeScript implementation of the mongodb_insert_document tool handler using MongoDB Node.js driver to insert a single document into a collection.private async mongodbInsertDocument( databaseName: string, collectionName: string, documentJson: string ) { const client = await this.getMongoClient(); try { const db = client.db(databaseName); const collection = db.collection(collectionName); const document = JSON.parse(documentJson); const result = await collection.insertOne(document); return { content: [ { type: "text", text: `Документ успешно вставлен в коллекцию "${collectionName}". ID: ${result.insertedId}`, }, ], }; } catch (error) { throw new Error( `Ошибка вставки документа: ${error instanceof Error ? error.message : String(error)}` ); } finally { await client.close(); } }
- src/server.py:217-237 (schema)Input schema for mongodb_insert_document tool in the Python server's tools list."name": "mongodb_insert_document", "description": "Inserts document into collection", "inputSchema": { "type": "object", "properties": { "databaseName": { "type": "string", "description": "Database name", }, "collectionName": { "type": "string", "description": "Collection name", }, "document": { "type": "string", "description": "JSON string with document to insert", }, }, "required": ["databaseName", "collectionName", "document"], }, },
- src/index.ts:230-249 (schema)Input schema for mongodb_insert_document tool in the TypeScript server's tools list.name: "mongodb_insert_document", description: "Вставляет документ в коллекцию", inputSchema: { type: "object", properties: { databaseName: { type: "string", description: "Имя базы данных", }, collectionName: { type: "string", description: "Имя коллекции", }, document: { type: "string", description: "JSON строка с документом для вставки", }, }, required: ["databaseName", "collectionName", "document"], },
- src/index.ts:359-364 (registration)Tool call dispatch/registration in the TypeScript server's CallToolRequest handler switch statement.case "mongodb_insert_document": return await this.mongodbInsertDocument( args?.databaseName as string, args?.collectionName as string, args?.document as string );