db.t_verify_stat.aggregate([
{
$match: {
updatedTime: {
$gte: ISODate("2023-02-06 00:44:20.000"),
$lte: ISODate("2023-02-06 01:44:20.000"),
}
}
}
,
{
$group: {
_id: "$operatorId",
"spentArray": {
$push: "$pullSpent"
}
}
}
,
{
$project: {
"operatorId": 1,
"spentArray": 1,
"size": {
$size: ["$spentArray"]
}
}
},
{
$project: {
"operatorId": 1,
"spentArray": 1,
"middleFloat": {
$divide: ["$size", 2]
}
}
},
{
$project: {
"operatorId": 1,
"spentArray": 1,
"truncValue": {
$trunc: ["$middleFloat"]
}
}
},
{
$project: {
"operatorId": 1,
"spentArray": 1,
"middle": {
$add: ["$truncValue", 1]
}
}
},
{
$project: {
"operatorId": 1,
"pullSpent": 1,
"middleValue": {
$arrayElemAt: ["$spentArray", "$middle"]
}
}
}
])
效果图:
![](https://img-blog.csdnimg.cn/img_convert/b6427d0ece59073207b62a4f8b2b59ea.png)