Hi, I am very new to MongoDB. We are using MongoDB in on-prem. We have a requirement where certain Document needs to be moved to another collection after few days (like history collection). What are the best ways to achieve this. I was preferring any automatic option instead of writing Java code etc. Please suggest. Thanks in advance
Hi @Siddhartha_Roy ,
There is no way to do so without scripting or coding.
You have the following options:
Use change streams to grab a document delete and write it to archive destination. With Atlas I used the triggers to do that:
Triggers Treats and Tricks: Cascade Document Delete Using Triggers Preimage
Use a $merge on the future deleted documents to write them to another collection than delete.
Write code , you can possibly use transactions where you read and offload data to archive , delete the old data and commit.