From 6c78829689f8addc26ef0b2ba8fb321e5d86733d Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Sat, 13 Feb 2021 10:40:20 -0500 Subject: [PATCH] fix(model): use schema-level default collation for indexes if index doesn't have collation Fix #9912 --- lib/model.js | 4 ++++ test/model.indexes.test.js | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/model.js b/lib/model.js index 04cb57a31c4..99002b330b3 100644 --- a/lib/model.js +++ b/lib/model.js @@ -1650,6 +1650,10 @@ function _ensureIndexes(model, options, callback) { if ('background' in options) { indexOptions.background = options.background; } + if (model.schema.options.hasOwnProperty('collation') && + !indexOptions.hasOwnProperty('collation')) { + indexOptions.collation = model.schema.options.collation; + } const methodName = useCreateIndex ? 'createIndex' : 'ensureIndex'; model.collection[methodName](indexFields, indexOptions, utils.tick(function(err, name) { diff --git a/test/model.indexes.test.js b/test/model.indexes.test.js index 74e10e97735..50ed7c86125 100644 --- a/test/model.indexes.test.js +++ b/test/model.indexes.test.js @@ -569,7 +569,6 @@ describe('model', function() { let indexes = yield User.listIndexes(); assert.equal(indexes.length, 2); assert.deepEqual(indexes[1].key, { username: 1 }); - console.log(indexes); assert.ok(indexes[1].collation); assert.equal(indexes[1].collation.strength, 2);