Sunday, 15 September 2013

mongodb - Removing mongo entry after a specific set of time in a Meteor application -



mongodb - Removing mongo entry after a specific set of time in a Meteor application -

i have database of time sensitive data. there "best practice" delete entry after x time? 30 minutes maybe 24 hours. i've thought intervals , stuff seems lazy solution eat resources quickly.

intervals right solution. however, not eat resources, safe against server restart, not create new interval each element want remove. instead, run 1 global interval clear elements in given period:

var clear = function() { var min = new date(new date() - duration); documents.remove({ createdat: {$lt: min} }); }; meteor.startup(function() { clear(); meteor.setinterval(clear, interval); });

where duration minimal number of miliseconds document should remain in db, , interval how perform purge.

mongodb meteor

No comments:

Post a Comment