Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix QuerySet.update() with unique fields #17

Merged
merged 1 commit into from
May 8, 2024

Conversation

timgraham
Copy link
Collaborator

fixes #14

collection = self.get_collection()
try:
criteria = self.build_query().mongo_query
except EmptyResultSet:
return 0
options = self.connection.operation_flags.get("update", {})
options = dict(options, **kwargs)
method = "update_many" if multi else "update_one"
return getattr(collection, method)(criteria, update_spec, **options).matched_count
return collection.update_many(criteria, update_spec, **options).matched_count
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍🏿

@timgraham timgraham marked this pull request as ready for review May 8, 2024 13:25
@timgraham timgraham merged commit df4003d into mongodb-labs:main May 8, 2024
3 checks passed
@timgraham timgraham deleted the update-bug-14 branch May 8, 2024 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QuerySet.update() only updates one document if the field is unique
2 participants