Added elemMatch
operator as well - match
is too obscure #653
This commit is contained in:
parent
f4aa546af8
commit
be3643c962
@ -6,6 +6,7 @@ Changelog
|
|||||||
Changes in 0.9.X - DEV
|
Changes in 0.9.X - DEV
|
||||||
======================
|
======================
|
||||||
|
|
||||||
|
- Added `elemMatch` operator as well - `match` is too obscure #653
|
||||||
- Added support for progressive JPEG #486 #548
|
- Added support for progressive JPEG #486 #548
|
||||||
- Allow strings to be used in index creation #675
|
- Allow strings to be used in index creation #675
|
||||||
- Fixed EmbeddedDoc weakref proxy issue #592
|
- Fixed EmbeddedDoc weakref proxy issue #592
|
||||||
|
@ -11,7 +11,7 @@ __all__ = ('query', 'update')
|
|||||||
|
|
||||||
|
|
||||||
COMPARISON_OPERATORS = ('ne', 'gt', 'gte', 'lt', 'lte', 'in', 'nin', 'mod',
|
COMPARISON_OPERATORS = ('ne', 'gt', 'gte', 'lt', 'lte', 'in', 'nin', 'mod',
|
||||||
'all', 'size', 'exists', 'not')
|
'all', 'size', 'exists', 'not', 'elemMatch')
|
||||||
GEO_OPERATORS = ('within_distance', 'within_spherical_distance',
|
GEO_OPERATORS = ('within_distance', 'within_spherical_distance',
|
||||||
'within_box', 'within_polygon', 'near', 'near_sphere',
|
'within_box', 'within_polygon', 'near', 'near_sphere',
|
||||||
'max_distance', 'geo_within', 'geo_within_box',
|
'max_distance', 'geo_within', 'geo_within_box',
|
||||||
@ -95,7 +95,7 @@ def query(_doc_cls=None, _field_operation=False, **query):
|
|||||||
if op in GEO_OPERATORS:
|
if op in GEO_OPERATORS:
|
||||||
value = _geo_operator(field, op, value)
|
value = _geo_operator(field, op, value)
|
||||||
elif op in CUSTOM_OPERATORS:
|
elif op in CUSTOM_OPERATORS:
|
||||||
if op == 'match':
|
if op in ('elem_match', 'match'):
|
||||||
value = field.prepare_query_value(op, value)
|
value = field.prepare_query_value(op, value)
|
||||||
value = {"$elemMatch": value}
|
value = {"$elemMatch": value}
|
||||||
else:
|
else:
|
||||||
|
@ -3604,6 +3604,9 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
ak = list(Bar.objects(foo__match={'shape': "square", "color": "purple"}))
|
ak = list(Bar.objects(foo__match={'shape': "square", "color": "purple"}))
|
||||||
self.assertEqual([b1], ak)
|
self.assertEqual([b1], ak)
|
||||||
|
|
||||||
|
ak = list(Bar.objects(foo__elemMatch={'shape': "square", "color": "purple"}))
|
||||||
|
self.assertEqual([b1], ak)
|
||||||
|
|
||||||
ak = list(Bar.objects(foo__match=Foo(shape="square", color="purple")))
|
ak = list(Bar.objects(foo__match=Foo(shape="square", color="purple")))
|
||||||
self.assertEqual([b1], ak)
|
self.assertEqual([b1], ak)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user