0

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.

2
  • This question is similar to: How do I manage MongoDB connections in a Node.js web application?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Mar 26 at 13:57
  • this question is related mongodb atlas serverless functions connection management, however given reference to similar question is related to connections management in node js application. Commented Mar 28 at 6:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.