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

Upsert inconsistency with pymongo (efficiency related) #336

Closed
akatrevorjay opened this issue May 25, 2013 · 1 comment
Closed

Upsert inconsistency with pymongo (efficiency related) #336

akatrevorjay opened this issue May 25, 2013 · 1 comment
Milestone

Comments

@akatrevorjay
Copy link

I originally asked a q @ https://groups.google.com/forum/?fromgroups#!topic/mongoengine-users/TE-WfVD1gZ4 about this.

Now that get_or_create is scheduled to be deprecated these days due to that race condition, the suggested alternative is to utilize upserts instead.

In the Mongo docs, it says that the query parameters will be merged with the update parameters if the document matching your query doesn't exist.
In MongoEngine, this appears to not be the case?

For instance:
self._status = EmailRecipientStatus.objects(email_address=self.email_address).update_one(upsert=True)

Results in:
OperationError: No update parameters, would remove data

Whereas this works, but this causes a write every time it's accessed (not to mention some ugly duplication):
self._status = EmailRecipientStatus.objects(email_address=self.email_address).update_one(upsert=True, set__email_address=self.email_address)

So, this issue is about making upserts match what pymongo does in the greatness that is MongoEngine =)

@rozza
Copy link
Contributor

rozza commented Jun 3, 2013

Hi this was added in 0.8 in #308 so you should be good to go!

@rozza rozza closed this as completed Jun 3, 2013
rozza added a commit that referenced this issue Jun 3, 2013
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

No branches or pull requests

2 participants