Skip to content

Commit c4c4245

Browse files
authored
Merge branch 'master' into transactions-global-session-ver
2 parents 7eee132 + 5a8b051 commit c4c4245

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

mongoengine/queryset/base.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,14 @@ def upsert_one(self, write_concern=None, read_concern=None, **update):
638638
document = self._document.objects.with_id(atomic_update.upserted_id)
639639
return document
640640

641-
def update_one(self, upsert=False, write_concern=None, full_result=False, **update):
641+
def update_one(
642+
self,
643+
upsert=False,
644+
write_concern=None,
645+
full_result=False,
646+
array_filters=None,
647+
**update,
648+
):
642649
"""Perform an atomic update on the fields of the first document
643650
matched by the query.
644651
@@ -651,6 +658,7 @@ def update_one(self, upsert=False, write_concern=None, full_result=False, **upda
651658
will force an fsync on the primary server.
652659
:param full_result: Return the associated ``pymongo.UpdateResult`` rather than just the number
653660
updated items
661+
:param array_filters: A list of filters specifying which array elements an update should apply.
654662
:param update: Django-style update keyword arguments
655663
full_result
656664
:returns the number of updated documents (unless ``full_result`` is True)
@@ -660,11 +668,18 @@ def update_one(self, upsert=False, write_concern=None, full_result=False, **upda
660668
multi=False,
661669
write_concern=write_concern,
662670
full_result=full_result,
671+
array_filters=array_filters,
663672
**update,
664673
)
665674

666675
def modify(
667-
self, upsert=False, full_response=False, remove=False, new=False, **update
676+
self,
677+
upsert=False,
678+
full_response=False,
679+
remove=False,
680+
new=False,
681+
array_filters=None,
682+
**update,
668683
):
669684
"""Update and return the updated document.
670685
@@ -684,6 +699,7 @@ def modify(
684699
:param remove: remove rather than updating (default ``False``)
685700
:param new: return updated rather than original document
686701
(default ``False``)
702+
:param array_filters: A list of filters specifying which array elements an update should apply.
687703
:param update: Django-style update keyword arguments
688704
"""
689705

@@ -722,6 +738,7 @@ def modify(
722738
sort=sort,
723739
return_document=return_doc,
724740
session=_get_session(),
741+
array_filters=array_filters,
725742
**self._cursor_args,
726743
)
727744
except pymongo.errors.DuplicateKeyError as err:

tests/queryset/test_queryset.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,22 @@ class Blog(Document):
615615

616616
assert testc_blogs.count() == 1
617617

618+
# modify
619+
Blog.drop_collection()
620+
621+
# update one
622+
Blog.objects.create(tags=["test1", "test2", "test3"])
623+
624+
new_blog = Blog.objects().modify(
625+
__raw__={"$set": {"tags.$[element]": "test11111"}},
626+
array_filters=[{"element": {"$eq": "test2"}}],
627+
new=True,
628+
)
629+
testc_blogs = Blog.objects(tags="test11111")
630+
assert new_blog == testc_blogs.first()
631+
632+
assert testc_blogs.count() == 1
633+
618634
Blog.drop_collection()
619635

620636
# update one inner list

0 commit comments

Comments
 (0)