Merge pull request #1737 from CalgaryMichael/remove-pushall
Removing the usage of the '$pushAll' operator
This commit is contained in:
commit
2121387aa2
@ -328,7 +328,7 @@ def update(_doc_cls=None, **update):
|
|||||||
value = {key: value}
|
value = {key: value}
|
||||||
elif op == 'addToSet' and isinstance(value, list):
|
elif op == 'addToSet' and isinstance(value, list):
|
||||||
value = {key: {'$each': value}}
|
value = {key: {'$each': value}}
|
||||||
elif op == 'push':
|
elif op in ('push', 'pushAll'):
|
||||||
if parts[-1].isdigit():
|
if parts[-1].isdigit():
|
||||||
key = parts[0]
|
key = parts[0]
|
||||||
position = int(parts[-1])
|
position = int(parts[-1])
|
||||||
@ -337,6 +337,12 @@ def update(_doc_cls=None, **update):
|
|||||||
if not isinstance(value, (set, tuple, list)):
|
if not isinstance(value, (set, tuple, list)):
|
||||||
value = [value]
|
value = [value]
|
||||||
value = {key: {'$each': value, '$position': position}}
|
value = {key: {'$each': value, '$position': position}}
|
||||||
|
else:
|
||||||
|
if op == 'pushAll':
|
||||||
|
op = 'push' # convert to non-deprecated keyword
|
||||||
|
if not isinstance(value, (set, tuple, list)):
|
||||||
|
value = [value]
|
||||||
|
value = {key: {'$each': value}}
|
||||||
else:
|
else:
|
||||||
value = {key: value}
|
value = {key: value}
|
||||||
else:
|
else:
|
||||||
|
@ -58,6 +58,17 @@ class TransformTest(unittest.TestCase):
|
|||||||
update = transform.update(LisDoc, pull__foo__in=['a'])
|
update = transform.update(LisDoc, pull__foo__in=['a'])
|
||||||
self.assertEqual(update, {'$pull': {'foo': {'$in': ['a']}}})
|
self.assertEqual(update, {'$pull': {'foo': {'$in': ['a']}}})
|
||||||
|
|
||||||
|
def test_transform_update_push(self):
|
||||||
|
"""Ensure the differences in behvaior between 'push' and 'push_all'"""
|
||||||
|
class BlogPost(Document):
|
||||||
|
tags = ListField(StringField())
|
||||||
|
|
||||||
|
update = transform.update(BlogPost, push__tags=['mongo', 'db'])
|
||||||
|
self.assertEqual(update, {'$push': {'tags': ['mongo', 'db']}})
|
||||||
|
|
||||||
|
update = transform.update(BlogPost, push_all__tags=['mongo', 'db'])
|
||||||
|
self.assertEqual(update, {'$push': {'tags': {'$each': ['mongo', 'db']}}})
|
||||||
|
|
||||||
def test_query_field_name(self):
|
def test_query_field_name(self):
|
||||||
"""Ensure that the correct field name is used when querying.
|
"""Ensure that the correct field name is used when querying.
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user