I have collection with below documents:
_id : "123"
name : "rahul"
age : 40
experience: "10"
_id : "124"
name : "manish"
age : 42
experience: "12"
I want to find the sum of all the ages and also experience:
I am using below query:
db.emp_data.aggregate({
$group:
{
_id: null,
totalCap: {
$sum: "$age",
},
},
})
But , i am getting empty records. What condition should i put in the _id field?