I am just started learning MEAN stack and I am stuck. I need to send the below query data to frontend.
router.get('/average', (req, res) => {
Employees.aggregate([
{ $match: { "position": "sen" } },
{
$group: {
_id: null,
average: {
$avg: "$salary"
}
}
}
]);
});
I have tried doing this but it didn't work
router.get('/average', (req, res) => {
Employees.find(function (err, docs) {
res.json(docs);
}).aggregate([
{ $match: { "position": "sen" } },
{
$group: {
_id: null,
average: {
$avg: "$salary"
}
}
}
]);
});