Sending the updated document to S3 using triggers

Hi All,
I have created a trigger that sends the newly added data to s3 bucket.
Now if the document is updated I need to send it. But I am not sure how do I send it.
When I set this database trigger it sends the entire collection instead of a single document. How do I do that sending just the updated document and not the entire collection?

exports = function (changeEvent) {

const datalake = context.services.get(“FDI”);
const db = datalake.db(“users”);
const events = db.collection(“users”);

const pipeline = [

 {
        "$out": {
           "s3": {
              "bucket": "mongodb-s3",
              "region": "us-east-1",
                 "filename": {"$concat": ["users/",{"$toString" :Date.now()},"/",{"$toString" : "$_id"}]},
              "format": {
                    "name": "json",
                    "maxFileSize": "10MiB",
                   
              }
           }
        }
  }

];

return events.aggregate(pipeline);
};

Hi @Nirmal_Patil ,

I would add a $match stage in the beginning getting only the _id of the effected changeEvent.documentKey._id I’d.

Look at the documentation of trigger event documents and let me know if you have trouble to code this.

Thanks
Pavel

1 Like