Remove old records in mongodb based on Month

后端 未结 5 1173
[愿得一人]
[愿得一人] 2020-12-30 04:13

I am trying to delete Older records present in my collection .

I have a collection named \"user_track\" , which consists of data in this format shown below

5条回答
  •  -上瘾入骨i
    2020-12-30 04:37

    I have found a solution to address this issue .

    var date=new Date();
    date.setDate(date.getDate() - 1);
    db.user_track.remove({"access_time":{"$lt":date}});
    

    I will make this run automatically by putting these lines in a bash file and scheduling that script using a cron tab .

    Please share your views if this is a valid solution or not ??

提交回复
热议问题