Skip to content
10 changes: 1 addition & 9 deletions pymongo/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,6 @@ def _convert_write_result(
elif operation == "update":
if "upserted" in result:
res["upserted"] = [{"index": 0, "_id": result["upserted"]}]
# Versions of MongoDB before 2.6 don't return the _id for an
# upsert if _id is not an ObjectId.
elif result.get("updatedExisting") is False and affected == 1:
# If _id is in both the update document *and* the query spec
# the update document _id takes precedence.
update = command["updates"][0]
_id = update["u"].get("_id", update["q"].get("_id"))
res["upserted"] = [{"index": 0, "_id": _id}]
return res
Comment on lines 171 to 174

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that the PR should be updated to reflect that there's this minor refactor here.



Expand Down Expand Up @@ -660,7 +652,7 @@ def _raise_document_too_large(operation: str, doc_size: int, max_size: int) -> N
else:
# There's nothing intelligent we can say
# about size for update and delete
raise DocumentTooLarge(f"{operation!r} command document too large")
raise DocumentTooLarge(f"{operation} command document too large")


# From the Client Side Encryption spec:
Expand Down
Loading
Loading