These objects can contain hundreds of key/value pairs and I only want to keep data from within the last 365 days.
Currently when I update the document (add new dates and remove old ones) I overwrite the entire object. However as these objects can be reasonably large I believe this is bloating my oplog.
Is there a better way to remove key/value pairs that are older than 365 days and add new dates at the same time without having to overwrite the entire object?
Hello @Callum_Boyd, Welcome to the MongoDB community forum,
I am not sure what query you are using for add dates and remove dates, I guess you are passing the whole object of dates in $set or $unset operators,
You have to use . dot notation along with the object name and key name, like this,
For add dates:
and this will enable you to write “Time Series Collection” where you can set the automatic deletion of documents after a certain amount of time. please check the following: