Re-create index when already exists #11666 #11750

This commit is contained in:
Jan Dvorak
2022-03-31 00:27:36 +02:00
committed by denihs
parent 0c2b886425
commit b40efd8eb8
3 changed files with 30 additions and 2 deletions

View File

@@ -1,3 +1,19 @@
## v.NEXT, 2022-04-XX
#### Highlights
#### Breaking Changes
N/A
#### Migration Steps
#### Meteor Version Release
* `mongo@1.15.0`
- If an index with the same name, but different options exists Meteor will re-create it instead of crashing.
- If there is an error Meteor will output a better message naming the collection and index where the error occured.
#### Independent Releases
## v2.7.1, 2022-03-31
#### Highlights

View File

@@ -757,7 +757,19 @@ Object.assign(Mongo.Collection.prototype, {
var self = this;
if (!self._collection.createIndex)
throw new Error('Can only call createIndex on server collections');
self._collection.createIndex(index, options);
try {
self._collection.createIndex(index, options);
} catch (e) {
if (e.message.includes('An equivalent index already exists with the same name but different options.')) {
import { Log } from 'meteor/logging';
Log.info(`Re-creating index ${index} for ${self._name} due to options mismatchs.`);
self._collection._dropIndex(index);
self._collection.createIndex(index, options);
} else {
throw new Meteor.Error(`An error occurred when creating an index for collection "${self._name}: ${e.message}`);
}
}
},
_dropIndex(index) {

View File

@@ -9,7 +9,7 @@
Package.describe({
summary: "Adaptor for using MongoDB and Minimongo over DDP",
version: '1.14.6'
version: '1.15.0'
});
Npm.depends({