I have a collections names locations with data structures like:
{
"_id" : ObjectId("4e95263f1783ae8487be26d4"),
"name" : "test 1",
"location" : {
"coordinate" : {
"latitude" : 40.731987,
"longitude" : -73.999701
},
"address": "xxxxxxx"
}
}
and want to make geo queries against location.coordinate field.
When I’m trying to add index I get following results:
$> db.locations.ensureIndex( { "location.coordinate" : "2d" } )
$> **** SyntaxError: syntax error (shell):0
Is it possible to use geospatial index for such structure?
Since mongodb is based on GeoJSON format, its better to have the longitude element first
In the mongodb geospatial page, you can see that in multiple places
and