-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Scoped Counters only working with a single reference_field #34
Comments
Can you please report exactly the error? Which key in which collection is marked as duplicate? |
Hi @jpolvora, did you manage to resolve this problem? I am getting the same behaviour when working with 2 reference fields. Works fine with a single reference field. |
Hi @ramiel. I have managed to reproduce my error in your test code. If you change the block of tests on lines 306 to 3045 as follows, you should experience the duplicate key error:
The error stack trace looks like this:
I am able to temporarily fix this by commenting out the index creation, but I suppose this is not ideal. This is happening because of the way mongoose is indexing the array. It seems to only reference the object id value and not a combination of the object id and the string value. Are you able to look into this? |
Thank you @ozzyknox for the detailed report. I'll definetely look at this soon |
Hi @ramiel. I have run an isolated test in MongDB where I changed the
changes to look like this (and succeeds on the insert of the second document):
I have tested this scenario with the same unique index applied and it seems to work well. I have also run some tests with a single attrtibute inside the I hope this can help you. |
Yes, thank you. I don't want to modify the array to an object. Not because is a bad solution but because I cannot release it without having a major release. This means I won't solve the problem for who's using the library now. I must solve it using the same index. Nonetheless thank you for discovering this |
I'm discovering that mongo, when you specify an index on an array field, create an index for "each" value (https://docs.mongodb.com/manual/core/index-multikey/). This means that this solution never worked. |
Version 5.0.0 should fix this issue. Please check |
I want to scope by a single reference_field is it possible? |
Given any model wich I want to scope by two reference_fields ['fieldA','fieldB'] this would give an error of mongo duplicate key.
The text was updated successfully, but these errors were encountered: