react get data from mongodb filter date younger than code example
Example: how to filter data from mongodb date in reactjs
ar moment = require ('moment')
function previous_year_artist(req, res, next) {
var dateTimeTofilter = moment().subtract(1, 'year');
var filter = {
"date_added": {
$gte: new Date(dateTimeTofilter._d)
}
};
db.collection.find(
filter
).toArray(function(err, result) {
if (err) return next(err);
res.send(result);
});
}