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

Support duplicate key validation on 'index: { unique: true} }' #58

Open
stanmolina opened this issue Sep 14, 2017 · 5 comments
Open

Support duplicate key validation on 'index: { unique: true} }' #58

stanmolina opened this issue Sep 14, 2017 · 5 comments

Comments

@stanmolina
Copy link

This is still an issue mccormicka/Mockgoose#58

I'm running Mockgoose 7.3.3

@javierfernandes
Copy link

Yeap, also expecting it to validate it but it doesn't :( Same version (7.3.3)

@jgeary
Copy link

jgeary commented Apr 24, 2018

also having this issue! please implement 🙏🏻

@winfinit
Copy link
Collaborator

can someone provide a working or not working sample that I can copy and paste, or better yet a test case? I don't anticipate that this issue is coming from mockgoose, because it is actually using a real instance of mongodb and just mocking a connection string. I vaguely remember someone talking about this several times before, and I think the issue was identified that indexes were not recreated.

@zoeesilcock
Copy link

For me it was happening because I was dropping the database between tests using mockgoose.helper.reset(). That method removes all data, but also the indexes.

As a quick workaround I found a way of regenerating the indexes for the specific mongoose model I was testing: Model.ensureIndexes();

I assume there is a better way of fixing this issue. At the very least perhaps there should be a note in the docs for reset that indexes need to be recreated?

@wangxuepeng
Copy link

wangxuepeng commented Sep 24, 2018

after reset, call below to reset the indexes will fix this problem:

await mockgoose.helper.reset()
const db = mongoose.connection
db.modelNames().map(async (model) => {
  await db.models[model].createIndexes()
})

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

6 participants