Skip to content

Commit 58f3376

Browse files
committed
test: add test for #9150
1 parent 999da5a commit 58f3376

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/model.indexes.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,28 @@ describe('model', function() {
470470
});
471471
});
472472

473+
it('skips automatic indexing on childSchema if autoIndex: false (gh-9150)', function() {
474+
const nestedSchema = mongoose.Schema({
475+
name: { type: String, index: true }
476+
}, { autoIndex: false });
477+
const schema = mongoose.Schema({
478+
nested: nestedSchema,
479+
top: { type: String, index: true }
480+
});
481+
let Model;
482+
483+
return Promise.resolve().
484+
then(() => {
485+
Model = db.model('Model', schema);
486+
return Model.init();
487+
}).
488+
then(() => Model.listIndexes()).
489+
then(indexes => {
490+
assert.equal(indexes.length, 2);
491+
assert.deepEqual(indexes[1].key, { top: 1 });
492+
});
493+
});
494+
473495
describe('discriminators with unique', function() {
474496
this.timeout(5000);
475497

0 commit comments

Comments
 (0)