Você pode usar
$filter
agregação para filtrar as searches
variedade db.collection.aggregate([
{ "$match": { "username": "admin" }},
{ "$project": {
"total": { "$size": "$searches" },
"lasthour": {
"$size": {
"$filter": {
"input": "$searches",
"as": "search",
"cond": {
"$and": [
{ "$gte": ["$$search", onehourago] },
{ "$lte": ["$$search", now] }
]
}
}
}
},
"today": {
"$size": {
"$filter": {
"input": "$searches",
"as": "search",
"cond": {
"$and": [
{ "$gte": ["$$search", yesterday] },
{ "$lte": ["$$search", now] }
]
}
}
}
}
}}
])