Skip to main content
Glama

Astra DB MCP Server

Official
BulkUpdateRecords.ts1.58 kB
import { db } from "../util/db.js"; import { Collection } from "@datastax/astra-db-ts"; type BulkUpdateRecordsArgs = { collectionName: string; records: Array<{ id: string; record: Record<string, any>; }>; }; type BulkUpdateRecordsResult = { message: string; updatedCount: number; }; export async function BulkUpdateRecords({ collectionName, records, }: BulkUpdateRecordsArgs): Promise<BulkUpdateRecordsResult> { const collection: Collection = db.collection(collectionName); // Create an array of update operations for bulkWrite const updateOperations = records.map(({ id, record }) => ({ updateOne: { filter: { _id: id }, update: { $set: record } } })); let updatedCount = 0; try { // Try to use bulkWrite for better performance if (typeof collection.bulkWrite === 'function') { // Use bulkWrite for batch processing const result = await collection.bulkWrite(updateOperations); // Get the count of modified documents updatedCount = result.modifiedCount || 0; } else { // Fallback to individual updateOne operations for (const { id, record } of records) { const result = await collection.updateOne({ _id: id }, { $set: record }); if (result.modifiedCount) { updatedCount += result.modifiedCount; } } } } catch (error) { console.error("Error in bulk update:", error); throw error; } return { message: `Successfully updated ${updatedCount} records`, updatedCount, }; } // 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