Remove old records in mongodb based on Month

后端 未结 5 1156
[愿得一人]
[愿得一人] 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:33

    Mongo has a TTL feature on collections, I think this is a nice solution to such cases:

    https://docs.mongodb.com/manual/tutorial/expire-data/

    Basically something like:

    db.log_events.createIndex( { "createdAt": 1 }, { expireAfterSeconds: 3600 } )

提交回复
热议问题