Skip to content

Commit

Permalink
fix(model): only warn on custom _id index if index only has _id key
Browse files Browse the repository at this point in the history
Fix #6650
  • Loading branch information
vkarpov15 committed Jul 4, 2018
1 parent 2decc5b commit ff08b9c
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/model.js
Expand Up @@ -1205,11 +1205,12 @@ function _ensureIndexes(model, options, callback) {
};

for (const index of indexes) {
if (index[0]._id != null) {
const err = new Error('Cannot specify a custom index on `_id`, ' +
const keys = Object.keys(index[0]);
if (keys.length === 1 && keys[0] === '_id') {
console.warn('mongoose: Cannot specify a custom index on `_id` for ' +
'model name "' + model.modelName + '", ' +
'MongoDB does not allow overwriting the default `_id` index. See ' +
'http://bit.ly/mongodb-id-index');
return done(err);
}
}

Expand Down

0 comments on commit ff08b9c

Please sign in to comment.