Skip to content

Commit

Permalink
fix(model): make syncIndexes() report error if it can't create an i…
Browse files Browse the repository at this point in the history
…ndex

Fix #9303
  • Loading branch information
vkarpov15 committed Aug 8, 2020
1 parent d0db150 commit c90c89e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ function _ensureIndexes(model, options, callback) {
model.emit('error', err);
}
model.emit('index', err || indexError);
callback && callback(err);
callback && callback(err || indexError);
};

for (const index of indexes) {
Expand Down
3 changes: 1 addition & 2 deletions test/model.indexes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ describe('model', function() {
assert.deepEqual(indexes[1].key, { username: 1 });
assert.ok(!indexes[1].collation);

userSchema = new mongoose.Schema({ username: String });
userSchema = new mongoose.Schema({ username: String }, { autoIndex: false });
userSchema.index({ username: 1 }, {
unique: true,
collation: {
Expand All @@ -569,7 +569,6 @@ describe('model', function() {
db.deleteModel('User');
User = db.model('User', userSchema, 'User');

yield User.init();
yield User.syncIndexes();

indexes = yield User.listIndexes();
Expand Down

0 comments on commit c90c89e

Please sign in to comment.