MongoDB
 SQL >> Database >  >> NoSQL >> MongoDB

Correggere $project e $match in un'aggregazione MongoDB

Proietta i campi che userai dopo

Se $match o $group fanno riferimento a campi non inclusi in $project, quei campi risulteranno mancanti. Includili esplicitamente.

Offer.aggregate([ { $project: { myyear: { $year: "$ending_date" }, carer_id: 1, status: 1, ending_date: 1 } }, { $match: { carer_id: req.params.carer_id, myyear: 2015, status: 3 } }, { $group: { _id: { year: { $year: "$ending_date" }, month: { $month: "$ending_date" } }, count: { $sum: 1 } } } ], function (err, res) { if (err) { // handle error } console.log(res); });