我具有将值分组的汇总,但我需要创建一个名为“ ticket”的新字段,他的值是“ totalServices”和“ totalValue”之间的分部
Schedule.aggregate([{
$match: {
store: req.body.store,
scheduleStart: {
$lte: start,
$gte: req.body.period
},
status: {
$in: resultStatus
}
}
},
{
$group: {
_id: {
name: "$employee.name",
id: "$employee.id"
},
totalValue: {
$sum: "$value"
},
totalServices: {
$sum: 1
},
totalComission: {
$sum: "$comissionValue"
}
}
},
{
$sort: sort
},
{
$skip: req.body.limit * req.body.page
}
此汇总的结果:
{
_id: {
id:"5b644e88120834468cff7025",
name: "Jonh"
},
totalValue: 35,
totalServices: 1,
totalComission: 25
}
我需要的结果
{
_id: {
id:"5b644e88120834468cff7025",
name: "Jonh"
},
totalValue: 35,
totalServices: 1,
totalComission: 25,
ticket: 35
}
我试图在$ group之后使用$ project进行该划分,但是这样做没有任何成功。