Skip to main content
Glama

Astra DB MCP Server

Official
BulkCreateRecords.ts1.32 kB
import { db } from "../util/db.js"; import { Collection } from "@datastax/astra-db-ts"; type BulkCreateRecordsArgs = { collectionName: string; records: Record<string, any>[]; }; type BulkCreateRecordsResult = { message: string; ids: string[]; }; 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, }; } // Made with Bob

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