Fixed problem of ordering when using near_sphere operator

This commit is contained in:
Matthieu Rigal 2015-06-21 03:24:05 +02:00
parent 5efabdcea3
commit d96fcdb35c
2 changed files with 2 additions and 8 deletions

View File

@ -128,7 +128,8 @@ def query(_doc_cls=None, _field_operation=False, **query):
mongo_query[key].update(value) mongo_query[key].update(value)
# $max/minDistance needs to come last - convert to SON # $max/minDistance needs to come last - convert to SON
value_dict = mongo_query[key] value_dict = mongo_query[key]
if ('$maxDistance' in value_dict or '$minDistance' in value_dict) and '$near' in value_dict: if ('$maxDistance' in value_dict or '$minDistance' in value_dict) and \
('$near' in value_dict or '$nearSphere' in value_dict):
value_son = SON() value_son = SON()
for k, v in value_dict.iteritems(): for k, v in value_dict.iteritems():
if k == '$maxDistance' or k == '$minDistance': if k == '$maxDistance' or k == '$minDistance':

View File

@ -182,13 +182,6 @@ class GeoQueriesTest(unittest.TestCase):
points = Point.objects(location__near_sphere=[-122, 37.5], points = Point.objects(location__near_sphere=[-122, 37.5],
location__max_distance=60 / earth_radius) location__max_distance=60 / earth_radius)
# This test is sometimes failing with Mongo internals non-sense.
# See https://travis-ci.org/MongoEngine/mongoengine/builds/58729101
try:
points.count()
except OperationFailure:
raise SkipTest("Sometimes MongoDB ignores its capacities on maxDistance")
self.assertEqual(points.count(), 2) self.assertEqual(points.count(), 2)
# Test query works with max_distance being farer from one point # Test query works with max_distance being farer from one point