Add clear comment and tests for positional push #1565
This commit is contained in:
@@ -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}}
|
||||
|
||||
Reference in New Issue
Block a user