Skip to content

Commit 5e18e18

Browse files
author
Adler Au
committed
propagate collation, hint, comment to PyMongo functions
propagate collation, hint, comment settings to corresponding PyMongo functions in update, delete and aggregate
1 parent 8d5a976 commit 5e18e18

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

mongoengine/queryset/base.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,20 @@ def delete(self, write_concern=None, _from_doc_delete=False, cascade_refs=None):
519519
write_concern=write_concern, **{"pull_all__%s" % field_name: self}
520520
)
521521

522+
kwargs = {}
523+
if self._hint not in (-1, None):
524+
kwargs["hint"] = self._hint
525+
if self._collation:
526+
kwargs["collation"] = self._collation
527+
if self._comment:
528+
kwargs["comment"] = self._comment
529+
522530
with set_write_concern(queryset._collection, write_concern) as collection:
523-
result = collection.delete_many(queryset._query, session=_get_session())
531+
result = collection.delete_many(
532+
queryset._query,
533+
session=_get_session(),
534+
**kwargs,
535+
)
524536

525537
# If we're using an unack'd write concern, we don't really know how
526538
# many items have been deleted at this point, hence we only return
@@ -582,6 +594,15 @@ def update(
582594
update["$set"]["_cls"] = queryset._document._class_name
583595
else:
584596
update["$set"] = {"_cls": queryset._document._class_name}
597+
598+
kwargs = {}
599+
if self._hint not in (-1, None):
600+
kwargs["hint"] = self._hint
601+
if self._collation:
602+
kwargs["collation"] = self._collation
603+
if self._comment:
604+
kwargs["comment"] = self._comment
605+
585606
try:
586607
with set_read_write_concern(
587608
queryset._collection, write_concern, read_concern
@@ -595,6 +616,7 @@ def update(
595616
upsert=upsert,
596617
array_filters=array_filters,
597618
session=_get_session(),
619+
**kwargs,
598620
)
599621
if full_result:
600622
return result
@@ -1388,8 +1410,18 @@ def aggregate(self, pipeline, *suppl_pipeline, **kwargs):
13881410
read_preference=self._read_preference, read_concern=self._read_concern
13891411
)
13901412

1413+
if self._hint not in (-1, None):
1414+
kwargs.setdefault("hint", self._hint)
1415+
if self._collation:
1416+
kwargs.setdefault("collation", self._collation)
1417+
if self._comment:
1418+
kwargs.setdefault("comment", self._comment)
1419+
13911420
return collection.aggregate(
1392-
final_pipeline, cursor={}, session=_get_session(), **kwargs
1421+
final_pipeline,
1422+
cursor={},
1423+
session=_get_session(),
1424+
**kwargs,
13931425
)
13941426

13951427
# JS functionality

0 commit comments

Comments
 (0)