Geo location query using DB api and mongo db

has anyone query spacial data using mongo db and the db api?

1 Like

Hi Jose

just put the following as a filter.

{“loc”: {"$near" : {"$geometry": {“type” : “Point”, “coordinates” : [lng,lat] }, “spherical” : “true” } }}

you should of course create a geo index in mongodb as follow:
db.collection.createIndexes( { loc: “2dsphere”})
where collection is the name of your mongodb collection (position in this example)

example of a Document in Position Collection:

{
"_id": ObjectId(“564a0db640da6a430ffbb851”),
“owner”: "user@example.com",
“ville”: “toronto”,
“loc”: [
-79.3831843,
43.653226
],

“comment”: “test toronto”
}

let me know if you need more help

julien

1 Like