I have a Mongo query with a sum but the field type is a string, So I need project the string like a number, Is this possible? The aggretation code:
{
$project: {
_id: 1,
data: 1
}
}, {
$group: {
count: {
$sum: 1
},
total_risk: {
$sum: "$data.selcars"
},
string_value: {
$push: {
risksCar: "$data.selcars",
}
}
}
This is the result:
{
"count" : 2,
"total_risk" : 0,
"string_value" : [
{
"risksCar" : "4"
},
{
"risksCar" : "3"
}
]
}