diff --git a/CHANGES_NEXT_RELEASE b/CHANGES_NEXT_RELEASE index 8f878f5f4..55f334c64 100644 --- a/CHANGES_NEXT_RELEASE +++ b/CHANGES_NEXT_RELEASE @@ -1,3 +1,4 @@ +- [cygnus-common] [MongoDB] fix error about reindex when datamodel changed - [cygnus-common] [Arcgis] check object_id ignore case (#2313) - [cygnus-common] [Arcgis] fix url quoted based on uniqueFieldType (#2311) - [cygnus-common] [SQL] Add Primary Key on Timestamp to Error Log table (#2302) 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 bacb6f940..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,7 +215,11 @@ public void createIndex(MongoDatabase db, String collectionName, BasicDBObject k try { db.getCollection(collectionName).createIndex(keys, options); } catch(Exception e) { - if (e.getMessage().contains("IndexOptionsConflict")) { + // 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()); createIndex(db, collectionName, keys, options); } else {