U kunt $filter
gebruiken
aggregatie om de searches
uit te filteren reeks
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] }
]
}
}
}
}
}}
])