I have a transaction table that is populated with holidays occupied by employees. I need help with the following sql script in mongodb.
select employee,month,year,count(distinct (holiday_type) from transactions group by employee,month,year
I need to use aggregation in mongodb and a mongo request like this was created and this gives me the wrong solution.
db.transactions.aggregate([ { "$group": { "_id": { "Month": { "$month" : "$date" }, "Year": { "$year" : "$date" }, "employee" : "$employee", "holiday_type" : "$holiday_type" }, "Count_of_Transactions" : { "$sum" : 1 } }} ]);
I am confused about using counting logic in mongodb. Any suggestion would be helpful
source share