node.js - Remove record WHERE it is older than 10 mins in MongoDB? -
i new node js , mongodb (coming sql background). trying implement function removes records in collection 'journeys' timestamp older 10 mins. have done far:
connection.open(function(err, connection) { var database = connection.db(database); database.collection(journey_collection, {}, function(err, journeys) { var = new date().gettime() / 1000 - 10 * 60; journeys.remove({timestamp : ???}, function(err, result) { if(err != null) console.log('a refresh error occurred'); connection.close(); }); }); });
am on right track? should putting in place of "???" ?
you're on right track.
your "???" should in form {$lt:varname}
var tenminutesold = new date() tenminutesold.setminutes(tenminutesold.getminutes()-10) journeys.remove({timestamp: {$lt:tenminutesold}}, function(err, result) {
Comments
Post a Comment