I've been breaking my head on this for a while now:
[
{
"_id": "12sdsd",
"TotalStudent": [
"10"
]
},
{
"_id": "22fdf",
"TotalStudent": [
"20"
]
}
]
I need to sum the two values after conversion from String to Integer. This doesn't work:
db.collection.aggregate([
{
$group: {
_id: "",
TotalStudents: {
$sum: {
$toInt: "$TotalStudent.0"
}
}
}
}
])
See the playground, what am I doing wrong? https://mongoplayground.net/p/Evm3tJUGmKa