I have aggregation with query as https://mongoplayground.net/p/jxaI7MAyBmJ
I have project type, count and empName by adding stages under data to filter with below 2 condition
- type as a2 and
- empName (type as a1) should need to equal with empName (type as a2).
db.collection.aggregate([
{
$facet: {
"data": [
{
$match: {
type: {
$in: [
"a1",
"a2"
]
}
}
},
{
$group: {
_id: {
emp_name: "$emp_name",
type: "$type"
},
count: {
$sum: 1
}
}
},
{
$project: {
empName: "$_id.emp_name",
type: "$_id.type",
count: 1,
_id: 0
}
}
//Have to ADD sub stages here with the above mentioned 2 condition
]
}
}
])
I tried on applying this condition however unable to resolve this.
Thanks in advance