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:

  1. either running job cron, remove documents older 12 hr. smthing db.collection.remove({"createdat" : {$gt : date.now() - 43200000}})
  2. create ttl index field, automatically cool things. db.collection.ensureindex( { "createdat": 1 }, { "expireafterseconds": 43200 } )

i prefer second solution.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -