Quantcast
Viewing latest article 26
Browse Latest Browse All 269

mongodb atlas functions consuming too many connections

I have a trigger set up on a database that fires a function whenever a new document is inserted. This function generates a summary from the full document and updates a collection in another database. It works well with small datasets, but during bulk insertions, it consumes all available database connections, causing bottlenecks for both external applications and MongoDB Atlas services.

When ordered: false, too many concurrent operations overwhelm the system. When ordered: true, updates are processed sequentially, leading to significant latency. I need help implementing connection limiting in the MongoDB Atlas function while maintaining unordered event processing.

I tried creating a global state to persist data, but since these are serverless functions, it didn’t work. I also attempted bulk processing, but I faced the same issue.

code snippet attached for reference.

const targetServiceName = "my-service";const targetDatabaseName = "my-db";const targetCollectionName = "my-collection";const collection = context.services    .get(targetServiceName)    .db(targetDatabaseName)    .collection(targetCollectionName);collection.updateOne(      { _id: new BSON.ObjectId(campaignId) },      updatePayload,      {        upsert: true,      },    );

this is related mongodb atlas serverless functions connection management, however given reference to similar question is related to connections management in node js application.


Viewing latest article 26
Browse Latest Browse All 269

Trending Articles