I have documents with GeoJSON points and I want to count them by "square" using the coordinates. In order to do this I subtract my latitude/longititude with the modulus of the same latitude/longitude and the dimension of the square.
I got an error :
"errmsg" : "$mod only supports numeric types, not Array and NumberDouble"
I don't understand because I use the dot notation to extract the latitude and the longitude. Why does it say it's an array ?
I had no problem using the same query but with coordinates stored into two different properties instead of inside the same array.
Example document :
{
"_id" : ObjectId("560dcd15491a065d6ab1085c"),
"nodeLoc" :
{
"type" : "Point",
"coordinates" :
[
2.352221,
48.856612
]
}
}
Aggregation :
db.collection.aggregate(
[
{
$group:
{
_id:
{
latGroup: {$subtract: ["$nodeLoc.coordinates.1", {$mod: ["$nodeLoc.coordinates.1", 0.5]}]},
lonGroup: {$subtract: ["$nodeLoc.coordinates.0", {$mod: ["$nodeLoc.coordinates.0", 0.5]}]},
},
count: {$sum: 1}
}
}
]
)
I expect a result like this :
latGroup : 2 lonGroup : 48,5 count : 1
...
Thanks in advance