-
Notifications
You must be signed in to change notification settings - Fork 1.2k
How do I skip duplicate documents in a bulk insert? #1465
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
Comments
Unfortunately before we can support the In the meantime, you can use
|
Thanks :-) |
Is this write_concern={'continue_on_error': True} not supported anymore? |
No its not... But I think it makes sense to re-open this so that support for |
Is there any workaround for this in current mongoengine release? |
For now I am using raw pymongo from mongoengine as a workaround for this. So for a mongoengine Document class DocClass you will access the underlying pymongo collection and execute query like below: from pymongo.errors import BulkWriteError
try:
doc_list = [doc.to_mongo() for doc in me_doc_list] # Convert ME objects to what pymongo can understand
DocClass._get_collection().insert_many(doc_list, ordered=False)
except BulkWriteError as bwe:
print("Batch Inserted with some errors. May be some duplicates were found and are skipped.")
print(f"Count is {DocClass.objects.count()}.")
except Exception as e:
print( { 'error': str(e) }) |
Anybody is working on this issue, or is it even in backlog? |
Does anyone has a way around for this? since |
I'm trying to insert documents in bulk, I have created a unique index in my collection and want to skip documents which are duplicate while doing bulk insertion. This can be accomplished with native mongodb function:
How can I achieve this in mongoengine?
The text was updated successfully, but these errors were encountered: