I've documents that stores data as strings. I would like to convert some of the fields into doubles.
I've already tried parseFloat, which worked, but I'm not interested in such high precision. Is there a way to convert string into a double?
I've documents that stores data as strings. I would like to convert some of the fields into doubles.
I've already tried parseFloat, which worked, but I'm not interested in such high precision. Is there a way to convert string into a double?
I think you want $toDouble
.
db.collection.aggregate([
{$group: {_id:{},
avg_pop: {$avg: {$toDouble: "$POPULATION"}} } }])