Skip to content

Commit 73cf2bd

Browse files
committed
Remplace $merge for update_many.
1 parent cc29068 commit 73cf2bd

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

django_mongodb/compiler.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -614,26 +614,8 @@ def execute_sql(self, result_type):
614614
if is_empty:
615615
rows = 0
616616
else:
617-
base_pipeline = [
618-
{"$match": criteria},
619-
{"$set": dict(values)},
620-
]
621-
count_pipeline = [*base_pipeline, {"$count": "count"}]
622-
pipeline = [
623-
*base_pipeline,
624-
{
625-
"$merge": {
626-
"into": self.collection_name,
627-
"whenMatched": "replace",
628-
"whenNotMatched": "discard",
629-
}
630-
},
631-
]
632-
with self.connection.connection.start_session() as session, session.start_transaction():
633-
result = next(self.collection.aggregate(count_pipeline), {"count": 0})
634-
self.collection.aggregate(pipeline)
635-
rows = result["count"]
636-
# rows = 0 if is_empty else self.update(values)
617+
rows = self.collection.update_many(criteria, [{"$set": dict(values)}]).matched_count
618+
637619
for query in self.query.get_related_updates():
638620
aux_rows = query.get_compiler(self.using).execute_sql(result_type)
639621
if is_empty and aux_rows:

0 commit comments

Comments
 (0)