db.accessRecord.aggregate([
{
$match: {
appId: 19,
requestPath: /yck/,
createTime: {
"$gte": "2021-01-01 00:00:00"
}
}
}
,
{
$project: {
"new_string": {
$substr: ["$createTime", 0, 10]
}
}
},
{
$group: {
_id: "$new_string",
num: {
$sum: 1
}
}
},{$sort: {_id: 1}}
])
找了半天,其实截取一下字符串就好了 $substr