I followed this post by @Blakes-Seven Mongodb aggregate $group for multiple date ranges
But I need to add an additional group by field \"$User.Account\" and I keep gett
You can follow below syntax to add another field in $group
expression
db.logs.aggregate([
{ "$match": {
"DateTime": { "$gte": ninetyDays },
"Orgname": /Inc/
}},
{ "$group": {
"_id": {
"User": "$User.Account",
"date": {
"$cond": [
{ "$lt": [ "$DateTime", sixtyDays ] },
"61-90",
{ "$cond": [
{ "$lt": [ "$DateTime", thirtyDays ] },
"31-60",
"01-30"
]}
]
}
},
"count": { "$sum": 1 },
}},
{ "$sort": { "count": -1 }},
{ "$limit": 25}
])