Skip to content

Exception in bulk insert  #1907

@iniyanp

Description

@iniyanp

oids = mongokls.objects.insert(mongo_objs_list,load_bulk=False)

Let's say I have created compound index in my db. so when I try to insert objects let say
object1
object2
object3

and both object2,object3 already present in db. In that case, object1 gets inserted successfully. but exception has been thrown. Because of that I don't know which object would be inserted.

Is there a way to know which object is inserted, when there is exception in other docs.?

Activity

MacHu-GWU

MacHu-GWU commented on Dec 27, 2019

@MacHu-GWU

@iniyanp check mongoengine_mate https://github.com/MacHu-GWU/mongoengine_mate-project#smart-insert---skip-primary-key-conflict

It uses an exponential algorithm to segregate your data chunk into small pieces if encountering PrimaryKey conflict. which is way more efficient when you don't know which document will break it.

# insert one document which breaks the batch insert
User(id=100, name="Obama").save()

# smart_insert, automatically handle NotUniqueError
User.smart_insert([
    User(id=1, name="Alice"),
    User(id=2, name="Bob"),
    ...
    User(id=1000, name="Zillow"),
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @erdenezul@iniyanp@MacHu-GWU

        Issue actions

          Exception in bulk insert · Issue #1907 · MongoEngine/mongoengine