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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -