Skip to content

Instantly share code, notes, and snippets.

@AdamCanady
Created April 30, 2016 13:53
Show Gist options
  • Save AdamCanady/171ca82bfc448cb3c55d4e6e0bc972f2 to your computer and use it in GitHub Desktop.
Save AdamCanady/171ca82bfc448cb3c55d4e6e0bc972f2 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();
};
};
@julian-r
Copy link

cool, but is there a tighter integration level?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment