mongodbmongodb-atlasmongodb-stitch

MongoDB Stitch trigger delay


Are there known delays with MongoDB Stitch triggers? I see a 1-2 minute gap between authentication events and trigger completion.

I have a simple Authentication Trigger which executes on Create. In other words, the trigger fires when a new user is added.

The trigger calls the function below to add the new user to a temporary collection.

exports = async function(authEvent) {
  const mongodb = context.services.get("mongodb-atlas");
  const newUsers = mongodb.db("DATABASE").collection("newUsers");

  const { user, time } = authEvent;
  const newUser = { ...user, eventLog: [ { "created": time } ], access: [{"status": "pending"}] };
  await newUsers.insertOne(newUser);
}

The results are shown below. The authEvent records user creation time as 11:40. However, the new document isn't inserted until 11:42.

inserted record

What's the reason for the delay?

Server Version: cloud-2.26.4UI Version: 3.25.3JS SDK Version: 3.4.0 Plan: M0


Solution

  • The cause of this delay was placement of the Atlas deployment in one region and the Stitch deployment in a different region.

    According to the MongoDB docs:

    Write operations to a linked MongoDB cluster are handled within a single region that you specify when you create your application.