Add clear comment and tests for positional push #1565

This commit is contained in:
Erdenezul Batmunkh
2017-07-31 18:32:34 +08:00
parent 433f10ef93
commit 34fca9d6f5
3 changed files with 24 additions and 17 deletions

View File

@@ -336,10 +336,11 @@ def update(_doc_cls=None, **update):
elif op == 'addToSet' and isinstance(value, list):
value = {key: {'$each': value}}
elif op == 'push':
if parts[-1].isdigit() and op == 'push':
if parts[-1].isdigit():
key = parts[0]
position = int(parts[-1])
# position modifier must appear with each.
# $position expects an iterable. If pushing a single value,
# wrap it in a list.
if not isinstance(value, (set, tuple, list)):
value = [value]
value = {key: {'$each': value, '$position': position}}