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
Support duplicate validation on index: { unique: true} }
#58
Comments
Managed to hack this with the following: my_model.schema.path('field').options.unique = true; |
@ydaniv can you supply an example? |
@mccormicka thanks for the response! I think it's not quite what I meant. In any case, mongod does raise a "duplicate key" error, so I expect it to also be supported for consistency. I think currently it's not supported in mockgoose, so it requires also extra implementation. Would you like me to try and tackle this? |
Hi @ydaniv can you add a test case? Then I would be able to understand the issue a bit better. Thanks |
@ydaniv I merged your branch but these tests also fail when I run them against a real MongoDB instance. Do you see the same if you run it against mongodb without mockgoose? |
@mccormicka yes, for me they also fail. The error I see in the mongod console is not propagated for some reason through Mongoose. Did you you notice that error in the console? |
Just as a note, compound uniques are also not being caught by mockgoose. Example: I can create two instances of MySchema model with the same name/server property. |
Has anyone had any luck with this issue? I'm finding that my unique indexes are being ignored when performing an update() using Mockgoose. The only way around this is using a save() which does throw a duplicate key error, however update() simply updates and allows a duplicate to exist whilst the actual MongoDB throws an error. |
5.0 honors indexes |
Thank you for following this up, has this been applied to the latest 5.0rc? |
For now Mockgoose requires setting
unique: true
explicitly on the field.mongod will throw 11000 error for
index: { unique: true} }
but Mockgoose ignores it and test relying on this error occurring will fail.The text was updated successfully, but these errors were encountered: