I am trying to make some triggers when insert or update some docuement in my collection but here i found a problem or i am doing something wrong…
when i create a function that updates the document it still running because i call again the update function, so this make a loop for update the date, is there any way to just update my document once after or before insert/update the document?
exports = function(changeEvent) {
const collection = context.services.get('mycluster').db("mydb").collection("mycollection");
collection
.updateOne(
{ _id: changeEvent.documentKey._id },
{ $set: { updatedDate: new Date() } }
)
.catch(err => console.error(`Failed to add updatedDate: ${err}`));
return;
};