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

Mongo.insert_many does not continue_on_error when it encounters a Mongo.WriteError #346

Open
toddholmberg opened this issue Sep 14, 2020 · 1 comment

Comments

@toddholmberg
Copy link

Hello. I am getting a Mongo.WriteError when using Mongo.insert_many/4 with [continue_on_error: true]. I am setting the _id field, so can expect a duplicate key error once in a while. I assumed that continue_on_error would proceed in face of write errors. This is mentioned in an elixirforum post: https://elixirforum.com/t/understanding-dialyzer-error-the-pattern-can-never-match-the-type/31553

In the post it is suggested that Mongo.WriteError be added as an additional return type.

@type result(t) :: :ok | {:ok, t} | {:error, Mongo.Error.t()}

should be (I think) something like:

@type result(t) :: :ok | {:ok, t} | {:error, Mongo.Error.t()} | {:error, Mongo.WriteError.t()}

In the end, I just want insert_many to continue inserting the remaining items when it encounters write errors. Is this a possible change?

@toddholmberg
Copy link
Author

toddholmberg commented Sep 17, 2020

A little more background: it appears that insert_many completes the insert up to the list member that causes the error. I recently tried to insert a list of documents, one of which caused a WriteError and the items in the tail of the list did not insert. I tested this by reversing the list, placing the tail messages in the head of the list, and the skipped messages inserted.

@toddholmberg toddholmberg changed the title Mongo.insert_many/ Mongo.insert_many does not continue_on_error when it encounters a Mongo.WriteError Sep 17, 2020
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

1 participant