diff --git a/CHANGELOG.md b/CHANGELOG.md index 065c1930..c2f1713f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.4.0-alpha.2 (WIP) + +* Drop the correct already-existing index when trying to create a similar one + ## 1.4.0-alpha.1 (2024-02-15) * Implement new settings system diff --git a/lib/app/datasource/mongo_datasource.js b/lib/app/datasource/mongo_datasource.js index b51b2d51..e3570f02 100644 --- a/lib/app/datasource/mongo_datasource.js +++ b/lib/app/datasource/mongo_datasource.js @@ -659,7 +659,7 @@ Mongo.setMethod(function _remove(model, query, options, callback) { * * @author Jelle De Loecker * @since 0.2.0 - * @version 1.3.17 + * @version 1.4.0 */ Mongo.setMethod(function _ensureIndex(model, index, callback) { @@ -696,11 +696,20 @@ Mongo.setMethod(function _ensureIndex(model, index, callback) { // Check for IndexOptionsConflict if (err.code === 85) { + let index_to_drop; + + if (err.message.includes('already exists with a different name:')) { + index_to_drop = err.message.after('different name:').trim(); + } + + if (!index_to_drop) { + index_to_drop = options.name; + } try { // Index already exists, drop it - await collection.dropIndex(options.name); + await collection.dropIndex(index_to_drop); // Try again await collection.createIndex(index_specs, options); diff --git a/package.json b/package.json index 2de268a2..f5c65c6b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "alchemymvc", "description": "MVC framework for Node.js", - "version": "1.4.0-alpha.1", + "version": "1.4.0-alpha.2", "author": "Jelle De Loecker ", "keywords": [ "alchemy",