Remove old records in mongodb based on Month

后端 未结 5 1150
[愿得一人]
[愿得一人] 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条回答
  •  礼貌的吻别
    2020-12-30 04:30

    You can give any Date with Javascript date

    db.user_track.remove( { access_time : {"$lt" : new Date(year, month_0_indexed, day)} })
    

    So for removing documents before 1 September 2013 your command should be

    db.user_track.remove( { access_time : {"$lt" : new Date(2013, 8, 1) } })
    

    September is the 9th month but the month field is zero indexed. So we make that as 8.

提交回复
热议问题