I easily can store geolocation Data into MongoDB with an Eve RESTful API Server running.
So I store data like:
loc : {
lng: 13.01111,
lat: 51.01111
}
Validation etc. works nicely.
But: I was unable to find a way to get geolocation data out of the REST API.
There are sample queries over there working fine at the command-line, but there seems to be no way to query the API a appropriate way.
- Is there a way to throw MongoDB like Queries against the REST API or
- which is the prefered way to customize the API for such a purpose.
To make things clear: There is already a 2d index and geoWithin queriey at the mongo-cmd are working fine.
It's just about how to query via the REST API.
It's not mentioned but it should be supported. I'm not into geo stuff but I just tried to issue a $near
query and it returned an operation failure because my database was missing the necessary 2dindex. This means that the command was correctly passed to the database.
If you are using a rest client like Postman the syntax should be something like this (I'm using $near
for simplicity):
?where={"loc": {"$near": {"$geometry":{"type": "Point", "coordinates": [13,51]}}, "$maxDistance": 100}}
If you are using app.get
method remember to json.loads
your query. Hope this helps.
Points in MongoDB can be stored as either GeoJSON Point Objects,
loc : {
type: 'Point',
coordinates: [13.0111, 51.0111]
};
or legacy coordinate pairs.
loc : [13.01111, 51.01111]
The collection should have an index (either 2dsphere or 2d, respectively) to handle queries efficiently.
I'm pretty sure EVE has a built-in geoWithin operator. It's just not working because you're querying an invalid location format.