How to truncate a number to 3 decimals
For 3 decimal rounding, you can use this formula.
$divide: [ {$trunc: { $multiply: [ "$$coordinate" , 1000 ] } }, 1000 ]
For example, with your sample data, and using this aggregation:
db.getCollection('Test2').aggregate([
{ $project :
{
"location.type" : "$location.type",
"location.coordinates" :
{
$map:
{
input: "$location.coordinates",
as: "coordinate",
in: { $divide: [ {$trunc: { $multiply: [ "$$coordinate" , 1000 ] } }, 1000 ] }
}
}
}
}
])
you can obtain the desired result.
{
"_id" : ObjectId("59f9a4c814167b414f6eb553"),
"location" : {
"type" : "Point",
"coordinates" : [
-74.005,
40.705
]
}
}