Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adrianolsk/611bd0568a136310a062286a3cd2e9ea to your computer and use it in GitHub Desktop.
Save adrianolsk/611bd0568a136310a062286a3cd2e9ea to your computer and use it in GitHub Desktop.
'use strict';
module.exports = function(app) {
return function(req, res, next) {
app.service('things').Model.aggregate([{
$match: {}
}, {
$project: {
year: {
$year: '$createdAt'
},
month: {
$month: '$createdAt'
},
day: {
$dayOfMonth: '$createdAt'
},
hour: {
$hour: '$createdAt'
},
minutes: {
$minute: '$createdAt'
},
"extraData.sentiment": 1
}
}, {
$group: {
_id: {
'year': '$year',
'month': '$month',
'day': '$day',
'hour': '$hour',
'minutes': '$minutes',
},
count: {
$sum: 1
},
sentiment: {
$avg: "$extraData.sentiment"
}
}
}], function(err, result) {
if (err) {
console.log(err);
res.sendStatus(500);
return;
}
res.send(result);
});
// next();
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment