In my mongodb collection testdata
, there is a field named insertTime
. Our goal is to remove data older than 60 days. Previously, to accomplish this, I would use the logic of finding the deletion date and then comparing it against the updateTime:
var date = new Date();
var daysToDeletion = 60;
var deletionDate = new Date(date.setDate(date.getDate() - daysToDeletion));
deletionDate = deletionDate.toISOString()
printjson(insertDate);
db.testdata.find({"insertTime":{ $lt: deletionDate}})
Now, I want to delete records older than each record's alive
time. The alive time is calculated as the sum of insertTime and endTime (60 days). Documents older than this alive time minus 60 days should be deleted. Any ideas on how to achieve this in mongodb find command query?
This is what I have come up with so far, but I am not sure if the syntax is correct:
db.testdata.find({"insertTime"+endTime:{ $lt: deletionDate}})
Any insights on how to accomplish this task using the MongoDB find command would be greatly appreciated.
Additional details and goals have been included in the post.
EDIT: Currently using AWS documentDB 4.0.0