Moving document from one collection to another

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:

  1. 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 | MongoDB

  2. Use a $merge on the future deleted documents to write them to another collection than delete.

  3. Write code , you can possibly use transactions where you read and offload data to archive , delete the old data and commit.

Thanks
Pavel