操作前的数据
我用的vue2
const cmd = db.command
const $= db.command.aggregate
db.collection('xqh_order_1v1').aggregate( ).addFields({
// 添加新字段month到输出的记录 month: {
//提取月份
$month: {
date: {
//时间戳转化为日期"2023-11-29T15:57:54.663Z"
$toDate: {
// 对时间戳字段进行相乘,这里为毫秒 $multiply: ["$creat_date", 1] },
// 也可以直接写成下面的,不用写$multiply // $toDate:"$creat_date" }
}
}
}).group({
//设置要分组的字段month为新添加到记录的字段 _id:{
"校区":"$home_campus",
"月份":"$month"},
//求和
count:$.sum(1) })
.end().then(res=>{ console.log(res.result.data)
})
操作后