db.t_verify_stat.aggregate([
{
$match: {
updatedTime: {
$gte: ISODate("2023-02-10 00:00:00"),
$lte: ISODate("2023-02-10 00:10:00"),
},
operatorId: 63,
dataType: 1
}
}
,
{
$group: {
_id: "$operatorId",
"operatorName": {
$first: "$operatorName"
},
"pullSpentArray": {
$push: "$pullSpent"
},
"personalSpentArray": {
$push: "$personalSpent"
},
"contentSpentArray": {
$push: "$contentSpent"
},
"totalCount": {
$sum: 1
}
}
},
{
$project: {
"totalCount": 1,
"filterPullArray": {
$filter: {
input: "$pullSpentArray",
as: "item",
cond: {
$lte: ["$$item", NumberInt("20")]
}
}
},
"filterPersonalArray": {
$filter: {
input: "$personalSpentArray",
as: "item",
cond: {
$lte: ["$$item", NumberInt("20")]
}
}
},
"filterContentArray": {
$filter: {
input: "$contentSpentArray",
as: "item",
cond: {
$lte: ["$$item", NumberInt("20")]
}
}
}
}
},
{
$project: {
"totalCount": 1,
"pullSize": {
$size: ["$filterPullArray"]
},
"personalSize": {
$size: ["$filterPersonalArray"]
},
"contentSize": {
$size: ["$filterContentArray"]
}
}
},
{
$project: {
"pull": {
$divide: ["$pullSize", "$totalCount"]
},
"personal": {
$divide: ["$personalSize", "$totalCount"]
},
"content": {
$divide: ["$contentSize", "$totalCount"]
}
}
}
])