'Does the return value of a MongoDB Atlas trigger function have meaning?
In MongoDB Atlas, you can create triggers. These allow javascript functions, with access to the Mongo database, to respond to events. (See the docs at https://www.mongodb.com/docs/atlas/triggers/ ).
Does the return value of this trigger function do anything?
When I run the function in test pane, the returned value is passed through EJSON.parse
, which appears to convert a JSON-like data structure into a MongoDB structure, and outputted to the console. Despite this, I can't find documentation on what the return value might do.
Perhaps it can be used to modify or update the document whose update caused the trigger to fire? Or does this have to be done via something like...
const coll = context.services.get("Cluster0").db("db_name").collection("coll_name");
if (!(
updateDescription && updateDescription.updatedFields
&& updateDescription.updatedFields["updatedFromTrigger"]
)){
coll.updateOne(
{_id: new BSON.ObjectId("" + changeEvent.documentKey._id) },
{$set: {"updatedFromTrigger": new Date().toISOString() }}
).then(res =>
console.log("res",JSON.stringify(res))
);
}
...similar to the default explanatory comment?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|