I want to run a query which gets all the documents which has the 'active' field as true and run a custom function on them which checks if the 'date' field inside the document is older than 10 days. If both of them are true then it will make the active field to false.
This is how my current code looks like:
db.ad.find( { $and : [ // Check if active is true and the $where clause also equals to true
{ 'active' : true
},
{ '$where' : function() { // Custom compare function
var date = new Moment(this.date); // gets the date from the current document
var date2 = new Moment();
return Math.abs(date.diff(date2, 'days')) > 10;
}
}
]},
function(err, result) {
// How to update the document here?
}
);
Can anyone tell me how to update the documents after the find query?