-
Notifications
You must be signed in to change notification settings - Fork 9
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
E11000 duplicate key error collection #44
Comments
Hello, Thank you for using RelMongo |
Hello, I have the same problem with a different annotation: OneToMany I have two documents, Parent <- OneToMany -> child . The child document has indexes. For design reasons, first I insert the children, then I create the parent, fill up the children field with already-saved documents, and save. The first time I save one Parent, all works, but if I insert a new Parent, Mongo throws the exception "Duplicate Key" (referencing the first unique index in the child document). If I remove the indexes, all works... Seems OneToMany doesn't work when indexes are present, or am I wrong doing something? |
Hello @santino83 can you check where the index is created, is it in the parent or child? |
Hello @santino83 @KOSSOKO , I've reproduced the error you had and presently the @indexed does not work properly when it is used on child associations with relmongo, in fact spring is considering the documents as embedded so it will create indexes in parent collections. A workaround to this is to create the indexes through mongoOperations (mongoTemplate) on the child class directly instead of using @indexed annotation like this :
I will keep this issue opened to try to find a solution to make @indexed work on child associations. Thank you and sorry for this. |
Thanks for your answer. Yes, it's a good workaround to create the index dynamically. I will try it and give a feedback. |
Thank you, I'll try the workaround too. Infact, the error was prettly clear, mongoTemplate tries to manipulate indexes, beacuse knows nothing about your annotation. I think it needs a lot of investigation to find out a robust solution to avoid this behavior. Thanks for your job |
I can confirm you that removing indexed annotations on child document fix the error. Obviously, I had to create indexes programmatically using mongoTemplate IndexOperations. I'll look forward to read news about a fix for this "bug". Thank you |
hi @santino83 @KOSSOKO , I released a candidate version 3.1.0-RC1 which include a fix, can you test it with @indexed annotation and give your feedback please. I will release the 3.1.0 version if your tests are concluding. |
I cannot reproduce the error, as I cannot use v3.1.0 in my main project (as it uses spring boot < 2). I've created a new project with just spring boot/spring starter mongo, embeeded mongodb and 2 documents, Parent and Child with OneToMany. I had different results, sometimes 3.0.1 throws error, sometimes no error. I'm only sure that 3.1.0-RC1 never throws errors (I tested with spring boot >= 2.0 < 2.2). Maybe I have some problem with my maven. Here is my code: Parent document:
Child document:
App configuration:
Test:
where ParentRepository and ChildRepository are simple mongoRepository interface. Pom (last i've used):
and it works with relmongo 3.0.1 and 3.1.0-RC1... log using 3.0.1:
log using 3.1.0-RC1:
I'll try again tomorrow |
Hello @santino83 ,
it's good news that it does not throw errors. I will release the final version soon. |
Hum, ok, so I need also to upgrade my Spring version from 2.2.0.RELEASE to 2.2.1.REALEASE to test. Ok, I will give test and give you a feedback |
The Final release RelMongo 3.1.0 has been published. |
Hi,
First thanks for the wonderfull plugin.
I have two classes Agency and Country with OneToOne relation
My use case :
Problem:
When I create a country with an agency to null, the first time it is good. The 2nd time, I got the error
This is probably do to the fact that I added in country
How is it possible to create all countries first with Agency to null, then to add for each country an agency ?
null is detected as key, in agency.agencyCode, but I don't want him to create cascade.
E11000 duplicate key error collection: gara-cash-transaction.country index: agency.agencyCode dup key: { agency.agencyCode: null }
Thanks in advance.
The text was updated successfully, but these errors were encountered: