I am trying to count distinct(not unique)
or Emp No
in same department
.but getting error
query failed: unknown group operator '$group'
here is my code https://mongoplayground.net/p/UvYF9NB7vZx
db.collection.aggregate([
{
$group: {
_id: "$Department",
total: {
"$group": {
_id: "$Emp No"
}
}
}
}
])
Expected output
[
{
"_id": "HUAWEI”,
“total”:1
},
{
"_id": "THBS”,
“total”:2
}
]
THBS
have two different Emp No
A10088P2C
and A20088P2C
HUAWEI
have only one Emp No
A1016OBW
$group
accumulator. Available accumulators are documented on docs.mongodb.com/manual/reference/operator/aggregation/group/….