Skip to content

Commit

Permalink
šŸ› Drop the correct already-existing index when trying to create a simā€¦
Browse files Browse the repository at this point in the history
ā€¦ilar one
  • Loading branch information
skerit committed Feb 19, 2024
1 parent 919d3ff commit 6611763
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 11 additions & 2 deletions lib/app/datasource/mongo_datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ Mongo.setMethod(function _remove(model, query, options, callback) {
*
* @author Jelle De Loecker <jelle@elevenways.be>
* @since 0.2.0
* @version 1.3.17
* @version 1.4.0
*/
Mongo.setMethod(function _ensureIndex(model, index, callback) {

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <jelle@elevenways.be>",
"keywords": [
"alchemy",
Expand Down

0 comments on commit 6611763

Please sign in to comment.