position support singular value #1565
This commit is contained in:
@@ -304,10 +304,6 @@ def update(_doc_cls=None, **update):
|
||||
value = {match: value}
|
||||
|
||||
key = '.'.join(parts)
|
||||
position = None
|
||||
if parts[-1].isdigit() and isinstance(value, (list, tuple, set)):
|
||||
key = parts[0]
|
||||
position = int(parts[-1])
|
||||
|
||||
if not op:
|
||||
raise InvalidQueryError('Updates must supply an operation '
|
||||
@@ -339,11 +335,18 @@ def update(_doc_cls=None, **update):
|
||||
value = {key: value}
|
||||
elif op == 'addToSet' and isinstance(value, list):
|
||||
value = {key: {'$each': value}}
|
||||
elif op == 'push' and isinstance(value, list):
|
||||
if position is not None:
|
||||
elif op == 'push':
|
||||
if parts[-1].isdigit() and op == 'push':
|
||||
key = parts[0]
|
||||
position = int(parts[-1])
|
||||
# position modifier must appear with each.
|
||||
if not isinstance(value, (set, tuple, list)):
|
||||
value = [value]
|
||||
value = {key: {'$each': value, '$position': position}}
|
||||
else:
|
||||
elif isinstance(value, list):
|
||||
value = {key: {'$each': value}}
|
||||
else:
|
||||
value = {key: value}
|
||||
else:
|
||||
value = {key: value}
|
||||
key = '$' + op
|
||||
|
||||
Reference in New Issue
Block a user