I have a db Data as follows
{ "_id" : ObjectId("5a2109572222085be93ef10d"), "name" : "data1", "date" : "2017-12-01T00:00.0Z", "status" : "COMPLETED"},{ "_id" : ObjectId("5a2109572222085be93ef10d"), "name" : "data1", "date" : "2017-12-01T00:00.0Z", "status" : "FAILED"} and I want an aggreagate output as follows
{ date:"2017-12-01T00:00:0Z", total:"2", completed:1, failed:1 }
I have tried this code but didn't produce the result as above
db.test.aggregate([ {$group: {_id : {date : '$date',status:'$status'}, total:{$sum :1}}}, {$project : {date : '$_id.date', status : '$_id.status', total : '$total', _id : 0}} ])
{ date:"2017-12-01T00:00:0Z", total:"2", completed:2, failed:0 }