Skip to main content
Glama

BulkCreateRecords

Insert multiple records into a specified collection in Astra DB databases using this tool. Streamline data management with a single API call, supporting efficient bulk operations.

Instructions

Create multiple records in a collection at once

Input Schema

NameRequiredDescriptionDefault
collectionNameYesName of the collection to create the records in
recordsYesArray of records to insert

Input Schema (JSON Schema)

{ "properties": { "collectionName": { "description": "Name of the collection to create the records in", "type": "string" }, "records": { "description": "Array of records to insert", "items": { "type": "object" }, "type": "array" } }, "required": [ "collectionName", "records" ], "type": "object" }

Implementation Reference

  • The main handler function that executes the bulk record creation logic, preferring insertMany for performance and falling back to individual insertOne calls if necessary.
    export async function BulkCreateRecords({ collectionName, records, }: BulkCreateRecordsArgs): Promise<BulkCreateRecordsResult> { const collection: Collection = db.collection(collectionName); let ids: string[] = []; try { // Try to use insertMany for better performance if (typeof collection.insertMany === 'function') { const result = await collection.insertMany(records); // Extract the inserted IDs from the result ids = Object.values(result.insertedIds || {}) .map((id) => id?.toString() || "") .filter((id) => id !== ""); } else { // Fallback to individual insertOne operations for (const record of records) { const result = await collection.insertOne(record); if (result.insertedId) { ids.push(result.insertedId.toString()); } } } } catch (error) { console.error("Error in bulk create:", error); throw error; } return { message: `Successfully created ${ids.length} records`, ids, }; }
  • TypeScript type definitions for the input arguments and output result of the BulkCreateRecords tool.
    type BulkCreateRecordsArgs = { collectionName: string; records: Record<string, any>[]; }; type BulkCreateRecordsResult = { message: string; ids: string[]; };
  • tools.ts:262-282 (registration)
    Registration of the BulkCreateRecords tool in the tools array exported for MCP listTools, including description and input JSON schema.
    { name: "BulkCreateRecords", description: "Create multiple records in a collection at once", inputSchema: { type: "object", properties: { collectionName: { type: "string", description: "Name of the collection to create the records in", }, records: { type: "array", description: "Array of records to insert", items: { type: "object", }, }, }, required: ["collectionName", "records"], }, },
  • index.ts:301-315 (registration)
    Dispatch logic in the main CallToolRequest handler that invokes the BulkCreateRecords function and formats the response.
    case "BulkCreateRecords": const bulkCreateResult = await BulkCreateRecords({ collectionName: args.collectionName as string, records: args.records as Record<string, any>[], }); return { content: [ { type: "text", text: `${ bulkCreateResult.message }\nIDs: ${bulkCreateResult.ids.join(", ")}`, }, ], };

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/datastax/astra-db-mcp'

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