I have an issue with aggregation code in Mongoose : (Error: Arguments must be aggregate pipeline operators)
This is my code :
This is for get all dates of one month past in parameter of the function.
async function getDatesFromMonth(month) {
Jour.aggregate([
{
$project: {"month" : {$month: "$date"}},
"date": "$date"
},
{
$match: {"month": month}
}
], (err,res)=>{
if(err) {
next(err);
} else {
console.log(res);
}
});
}
What i want (example) : When i pass 3 in parameters i want to get all the march dates of my db. :)
答案 0 :(得分:0)
这是很好的代码。
async function getDatesFromMonth(month) {
return Jour.aggregate([
{
$project: {month : {$month: "$date"}, date: "$date"},
},
{
$match: {"month": month}
},
{
$sort: {"date" :1}
}
])
}