mongodb - monogdb collection cleanup older than 12 hrs -
someone please suggest command cleanup mongodb collection events older 12 hrs.
i need configure part of cronjob, , executing @ every 12.00 pm , 12.00 am.
thanks,
first, need store creation date , time in documents. create additional field, if not have it. having field collection, have 2 options:
- either running job cron, remove documents older 12 hr. smthing
db.collection.remove({"createdat" : {$gt : date.now() - 43200000}})
- create ttl index field, automatically cool things.
db.collection.ensureindex( { "createdat": 1 }, { "expireafterseconds": 43200 } )
i prefer second solution.
Comments
Post a Comment