Created
April 30, 2016 13:53
-
-
Save AdamCanady/171ca82bfc448cb3c55d4e6e0bc972f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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
cool, but is there a tighter integration level?