Reputation: 9106
I'm having trouble getting Mongoengine's geospatial query to work. I've got a User
mongoengine class with with a field called cached.geoLoc
which is of the mongoengine type PointField()
. If I call
User.objects(cached__geoLoc__near=[100,100])
Then it returns answers. But if I want to restrict the results to a limited radius and call:
User.objects(cached__geoLoc__near=[100,100], cached__geoLoc__max_distance=1000)
then I get an error: pymongo.errors.OperationFailure: database error: Can't canonicalize query: BadValue geo near accepts just one argument when querying for a GeoJSON point. Extra field found: $maxDistance: 1000
I'm using MongoEngine version 0.8.7 and MongoDB 2.4 What could be the problem?
Upvotes: 0
Views: 1146
Reputation: 151112
I'm screaming bug here.
If I try this on a similar set of data with something like the following:
class Geo(Document):
loc = PointField()
result = Geo.objects(loc__near=[3,6], loc__max_distance=1000)
Then the resulting query issued to MongoDB is this:
{
"loc" : {
"$near" : {
"$geometry" : {
"type" : "Point",
"coordinates" : [ 3, 6 ]
}
},
"$maxDistance" : 1000
}
}
With the problem being the $maxDistance
modifier being in the wrong place.
The correct query form issued using the raw pymongo driver commands works fine:
result = Geo._get_collection().find({
"loc": {
"$near": {
"$geometry": {
"type": "Point",
"coordinates": [3,6]
},
"$maxDistance": 1000
}
}
}):
And mostly because we are issuing the $maxDistance
modifier where it should be which is "within" the $near
operator arguments.
File a bug. But you can use the direct syntax to get results as a work-around until there is a fix.
Upvotes: 2