Skip to content

Commit

Permalink
fix(model): fix syncIndexes() error when db index has a collation b…
Browse files Browse the repository at this point in the history
…ut Mongoose index does not

Fix #9224
  • Loading branch information
vkarpov15 committed Jul 10, 2020
1 parent 9ec30b8 commit d4c8859
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/helpers/indexes/isIndexEqual.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
const get = require('../get');
const utils = require('../../utils');

/**
* Given a Mongoose index definition (key + options objects) and a MongoDB server
* index definition, determine if the two indexes are equal.
*
* @param {Object} key the Mongoose index spec
* @param {Object} options the Mongoose index definition's options
* @param {Object} dbIndex the index in MongoDB as returned by `listIndexes()`
* @api private
*/

module.exports = function isIndexEqual(key, options, dbIndex) {
// If these options are different, need to rebuild the index
const optionKeys = [
Expand All @@ -17,8 +27,8 @@ module.exports = function isIndexEqual(key, options, dbIndex) {
continue;
}
if (key === 'collation') {
if (!(key in options) || !(key in dbIndex)) {
return false;
if (options.key == null || dbIndex.key == null) {
return options.key == null && dbIndex.key == null;
}
const definedKeys = Object.keys(options.collation);
const schemaCollation = options.collation;
Expand Down

0 comments on commit d4c8859

Please sign in to comment.