mongodb_create_collection
Create a new collection in a specified MongoDB database to organize and store data for your application.
Instructions
Создает новую коллекцию в указанной базе данных
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| databaseName | Yes | Имя базы данных | |
| collectionName | Yes | Имя коллекции |
Implementation Reference
- src/index.ts:671-693 (handler)The handler function that implements the core logic for the 'mongodb_create_collection' tool. It connects to MongoDB, creates the specified collection in the given database, and returns a success message or throws an error.private async mongodbCreateCollection( databaseName: string, collectionName: string ) { const client = await this.getMongoClient(); try { const db = client.db(databaseName); await db.createCollection(collectionName); return { content: [ { type: "text", text: `Коллекция "${collectionName}" успешно создана в базе данных "${databaseName}"`, }, ], }; } catch (error) { throw new Error( `Ошибка создания коллекции: ${error instanceof Error ? error.message : String(error)}` ); } finally { await client.close(); }
- src/server.py:451-464 (handler)The handler function that implements the core logic for the 'mongodb_create_collection' tool. It connects to MongoDB, creates the specified collection, and returns a success message.def mongodb_create_collection(database_name: str, collection_name: str) -> str: """Creates collection in database""" client = MongoClient(MONGODB_URI) try: db = client[database_name] db.create_collection(collection_name) return ( f'Collection "{collection_name}" successfully created ' f'in database "{database_name}"' ) except Exception as e: raise Exception(f"Error creating collection: {str(e)}") finally: client.close()
- src/index.ts:180-195 (schema)The input schema definition for the 'mongodb_create_collection' tool, used in tools/list response for registration.name: "mongodb_create_collection", description: "Создает новую коллекцию в указанной базе данных", inputSchema: { type: "object", properties: { databaseName: { type: "string", description: "Имя базы данных", }, collectionName: { type: "string", description: "Имя коллекции", }, }, required: ["databaseName", "collectionName"], },
- src/server.py:167-183 (schema)The input schema definition for the 'mongodb_create_collection' tool, returned in the tools/list endpoint."name": "mongodb_create_collection", "description": "Creates new collection in specified database", "inputSchema": { "type": "object", "properties": { "databaseName": { "type": "string", "description": "Database name", }, "collectionName": { "type": "string", "description": "Collection name", }, }, "required": ["databaseName", "collectionName"], }, },
- src/index.ts:344-348 (registration)The dispatch case in the tool call handler that routes to the mongodbCreateCollection method.case "mongodb_create_collection": return await this.mongodbCreateCollection( args?.databaseName as string, args?.collectionName as string );