fhen
一个分组查询的例子:

model.aggregate([{$match: ops}, {$unwind: \'$details\'}, {$sort: {create_at: -1}}, {
$group: {
_id: {
promotion_id: "$promotion_id",
product_id: \'$details.product_id\',
need_pay: \'$need_pay\'
},
product_name: {$first:"$details.name"},
price: {$max: "$details.price"},
amount: {$sum: "$details.amount"},
packing: {$sum: "$details.packing"},
quantity: {$sum: "$details.quantity"}
}
}, {$match: ops2}, {
$group: {
_id: {
promotion_id: "$_id.promotion_id",
need_pay: \'$_id.need_pay\'
},
details: {
$push: {
product_id: "$_id.product_id",
name: \'$product_name\',
price: \'$price\',
amount: \'$amount\',
packing: \'$packing\',
quantity: \'$quantity\'
}
}
}
}], fn);

分类:

技术点:

相关文章:

  • 2021-08-05
  • 2022-01-05
  • 2021-11-09
  • 2022-01-19
  • 2021-12-23
  • 2022-02-09
  • 2021-04-11
  • 2021-12-05
猜你喜欢
  • 2022-12-23
  • 2021-11-30
  • 2022-01-25
  • 2021-12-29
  • 2022-01-14
  • 2022-12-23
相关资源
相似解决方案