Ensure $maxDistance is always the last part of the query (#179)
This commit is contained in:
parent
692f00864d
commit
3364e040c8
@ -1,5 +1,7 @@
|
||||
from collections import defaultdict
|
||||
|
||||
from bson import SON
|
||||
|
||||
from mongoengine.common import _import_class
|
||||
from mongoengine.errors import InvalidQueryError, LookUpError
|
||||
|
||||
@ -123,6 +125,16 @@ def query(_doc_cls=None, _field_operation=False, **query):
|
||||
elif key in mongo_query:
|
||||
if key in mongo_query and isinstance(mongo_query[key], dict):
|
||||
mongo_query[key].update(value)
|
||||
# $maxDistance needs to come last - convert to SON
|
||||
if '$maxDistance' in mongo_query[key]:
|
||||
value_dict = mongo_query[key]
|
||||
value_son = SON()
|
||||
for k, v in value_dict.iteritems():
|
||||
if k == '$maxDistance':
|
||||
continue
|
||||
value_son[k] = v
|
||||
value_son['$maxDistance'] = value_dict['$maxDistance']
|
||||
mongo_query[key] = value_son
|
||||
else:
|
||||
# Store for manually merging later
|
||||
merge_query[key].append(value)
|
||||
|
Loading…
x
Reference in New Issue
Block a user