我有以下MongoDB查询:
const vaccination = await Schedule.aggregate([
{ $match: { status: ScheduleStatus.Published } },
{ "$unwind": { "path": "$vaccines", "preserveNullAndEmptyArrays": true } },
{
"$group": {
"_id": "$vaccines.vaccine",
"count": { "$sum": "$vaccines.stok" },
}
},
{
$lookup: { from: 'vaccines', localField: '_id', foreignField: '_id', as: 'vaccine' },
},
{
$project: {
"count": 1,
"vaccine": { "$arrayElemAt": ["$vaccine.name", 0] }
}
}
]);
并返回以下结果:
[
{
"_id": "61efd8a812432135c08a748d",
"count": 20,
"vaccine": "Sinovac"
}
]
有没有办法让输出成为一个值数组,比如:
[["Sinovac",20]]
谢谢,对不起,我英语不好