Forked from AdamCanady/Mongo aggregation in feathers.js
Created
May 16, 2017 19:57
-
-
Save adrianolsk/611bd0568a136310a062286a3cd2e9ea 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