Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

`index: true` and `unique: true` clash #1004

evdb opened this Issue Jul 11, 2012 · 0 comments


None yet
2 participants

evdb commented Jul 11, 2012

If you specify both unique: true and index: true in a schema field definition the unique is silently ignored. This test code demonstrates it:

# insert at line 913 of test/schema.test.js
var T25a = new Schema({
    name: { type: String, unique: true, index: true }
assert.deepEqual(T25a.path('name')._index, { unique: true });

# run the same test again with the order reversed in a possibly futile attempt to ensure that the issue is caught
var T25b = new Schema({
    name: { type: String, index: true, unique: true,  }
assert.deepEqual(T25b.path('name')._index, { unique: true });

I'd expect that either a unique index be created, or a warning be produced. Especially annoying is that reversing the order in the definition make the index be created as expected (on my machine at least). This makes the bug only occur occasionally.

@evdb evdb referenced this issue Jul 11, 2012


indexing #984

@aheckmann aheckmann closed this in 585e736 Jul 13, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment