diff --git a/cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/mongo/MongoBackendImpl.java b/cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/mongo/MongoBackendImpl.java index 14664d212..9b263e01e 100644 --- a/cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/mongo/MongoBackendImpl.java +++ b/cygnus-common/src/main/java/com/telefonica/iot/cygnus/backends/mongo/MongoBackendImpl.java @@ -215,6 +215,9 @@ public void createIndex(MongoDatabase db, String collectionName, BasicDBObject k try { db.getCollection(collectionName).createIndex(keys, options); } catch(Exception e) { + // Our guess is: + // IndexOptionsConflict -> when the same index (name and keys) already exits + // IndexKeySpecsConflict -> when an index with the same name but different keys (i.e. DM was changed) already exist if (e.getMessage().contains("IndexOptionsConflict") || e.getMessage().contains("IndexKeySpecsConflict")) { db.getCollection(collectionName).dropIndex(options.getName());