Atlas triggers, not working with async await

I want to firstly check the difference between atlas triggers and realm-triggers, as the docs for atlas triggers now quote realm.

however i have atlas collection insert trigger which works fine, however when i try to update my code with async await, and run the code, the result is not as expected.

for example i am using a package that returns a promise (bluebird)
and when i await xxxx
the result is {“isFulfilled”:false,“isRejected”:false}
while i am not getting promise pending, nor the actual result, the above result shows me that the result has not yet returned even though i am using async await.

if i replace await with

.then((resp) => {

this works, and the result is shown.

so the problem is with async await… are there any issues with async await with mongo db atlas triggers?

Hi @Rishi_uttam ,

First the Atlas triggers are based on Realm triggers. In fact it creates a dedicated realm app for you behind the scenes for convenience.

Now to use async in a trigger function you need to define it in the header of the function.

The below article has some examples:
Triggers Treats and Tricks: Cascade Document Delete Using Triggers Preimage


Hi Pavel, Thanks

Yes i thought that behind the scens it is using realm triggers.

The main problem is async await, i do know how to use it, and i do put async in the code. The problem is i am using a package called ‘clearbit’ which i have uploaded as a dependency. When i await clearbit the result shows as : [{“isFulfilled”:false,“isRejected”:false}]"

But when use a normal .then , .catch, the code works as expected.

When testing on my local node machine, i found that async /await works fine, its only with mongodb triggers with the clearbit package async await does not work… – do you have any ideas? i know the package is using bluebird and needle under the hood to return the promise.

Can you please navigate to your Realm trigger in the UI and copy paste me the link in the browser :slight_smile: