You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 =)
The text was updated successfully, but these errors were encountered:
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 =)
The text was updated successfully, but these errors were encountered: