diff --git a/lib/model.js b/lib/model.js index 5ff590a4e15..26dd0ea674e 100644 --- a/lib/model.js +++ b/lib/model.js @@ -1633,9 +1633,15 @@ function _ensureIndexes(model, options, callback) { const indexFields = utils.clone(index[0]); const indexOptions = utils.clone(index[1]); - const textBlock = Object.keys(indexFields).map(function(key) { - return indexFields[key]; - }); + const textBlock = () => { + const results = Object.keys(indexFields).map(function(key) { + return indexFields[key]; + }); + if (!results.includes('text')) { + return true; + } + return false; + }; delete indexOptions._autoIndex; _decorateDiscriminatorIndexOptions(model, indexOptions); if ('safe' in options) { @@ -1655,7 +1661,7 @@ function _ensureIndexes(model, options, callback) { indexOptions.background = options.background; } if (model.schema.options.hasOwnProperty('collation') && - !indexOptions.hasOwnProperty('collation') && textBlock != 'text') { + !indexOptions.hasOwnProperty('collation') && textBlock()) { indexOptions.collation = model.schema.options.collation; }