Skip to main content
Glama

BulkUpdateRecords

Update multiple records within a specified collection simultaneously using ID-based data modifications, streamlining batch operations for Astra DB databases.

Instructions

Update multiple records in a collection at once

Input Schema

NameRequiredDescriptionDefault
collectionNameYesName of the collection containing the records
recordsYesArray of records to update with their IDs

Input Schema (JSON Schema)

{ "properties": { "collectionName": { "description": "Name of the collection containing the records", "type": "string" }, "records": { "description": "Array of records to update with their IDs", "items": { "properties": { "id": { "description": "ID of the record to update", "type": "string" }, "record": { "description": "The updated record data", "type": "object" } }, "required": [ "id", "record" ], "type": "object" }, "type": "array" } }, "required": [ "collectionName", "records" ], "type": "object" }

Implementation Reference

  • The core handler function that executes bulk updates on records in an Astra DB collection, preferring bulkWrite for efficiency or falling back to individual updates, returning the update count and success message.
    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, }; }
  • JSON Schema definition for the BulkUpdateRecords tool input parameters used in MCP tool listing and validation.
    { name: "BulkUpdateRecords", description: "Update multiple records in a collection at once", inputSchema: { type: "object", properties: { collectionName: { type: "string", description: "Name of the collection containing the records", }, records: { type: "array", description: "Array of records to update with their IDs", items: { type: "object", properties: { id: { type: "string", description: "ID of the record to update", }, record: { type: "object", description: "The updated record data", }, }, required: ["id", "record"], }, }, }, required: ["collectionName", "records"], }, },
  • index.ts:317-332 (registration)
    Dispatches the CallToolRequest for BulkUpdateRecords by invoking the handler function and formatting the response for MCP.
    case "BulkUpdateRecords": const bulkUpdateResult = await BulkUpdateRecords({ collectionName: args.collectionName as string, records: args.records as Array<{ id: string; record: Record<string, any>; }>, }); return { content: [ { type: "text", text: bulkUpdateResult.message, }, ], };

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