Function aggregate with out stage

I’ve created a function with an aggregate on a collection. The last stage is the $out.

When I run the function in the function editor, the function create the collection in the $out stage.

When I create a trigger that schedules the function. The function doesn’t seems to work, there is no collection created.

All seems configured correct, but off course I’m missing something. Anyone some pointerd for me to look at?

thnx

Nanno

Hi Nanno,

What is the authentication . method defined on the function?

Make sure it is set to SYSTEM, $otherwise not sure the $out can work otherwise.

Also can you send us the link to the relevant trigger?

Thanks,
Pavel

Hi Pavel,

in the settings of the function, the authentication is set to System.

@Pavel_Duchovny Can I send you the link to the function in a DM? Or do have to post it here?

thnanks,
Nanno

Hi @Nanno_Scheringa,

Sure you can send me a DM…

Regards,
Pavel

Hi @Pavel_Duchovny,

don’t see how I can send you a DM in the community.

So this is the link to the trigger: Cloud: MongoDB Cloud

regards,
Nanno

Hi @Nanno_Scheringa,

I see that the trigger works fast and not producing any errors. I am afraid its due to the asynchronous logic of a return command used in the function not allowing the $out to complete.

Can you edit the function as following:

exports = async function() { 
...
...
var aggResult =  await shipmentsCollection.aggregate(pipeline).toArray();
return aggResult;

Let me know how that works.

Best regards,
Pavel

1 Like

Hi @Pavel_Duchovny

I changed the function as mentioned. And now I’m getting the results I’m expecting. Great!

Thanx for the support and your help.

Regards
Nanno

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.