diff --git a/lib/model.js b/lib/model.js index 0111fc8b12f..d61edf6f5b7 100644 --- a/lib/model.js +++ b/lib/model.js @@ -987,10 +987,7 @@ Model.init = function init(callback) { const autoIndex = this.schema.options.autoIndex; this.$init = new Promise((resolve, reject) => { if (autoIndex || (autoIndex == null && this.db.config.autoIndex)) { - const options = { - _automatic: true, - createIndex: this.base.options.useCreateIndex - }; + const options = { _automatic: true }; this.ensureIndexes(options, function(error) { if (error) { return reject(error); @@ -1211,6 +1208,10 @@ Model.createIndexes = function createIndexes(options, callback) { return this.ensureIndexes(options, callback); }; +/*! + * ignore + */ + function _ensureIndexes(model, options, callback) { const indexes = model.schema.indexes(); @@ -1271,7 +1272,10 @@ function _ensureIndexes(model, options, callback) { applyWriteConcern(model.schema, indexOptions); indexSingleStart(indexFields, options); - const methodName = options.createIndex ? 'createIndex' : 'ensureIndex'; + const useCreateIndex = 'createIndex' in options ? + options.createIndex : + model.base.options.useCreateIndex; + const methodName = useCreateIndex ? 'createIndex' : 'ensureIndex'; model.collection[methodName](indexFields, indexOptions, utils.tick(function(err, name) { indexSingleDone(err, indexFields, indexOptions, name); if (err) {