Skip to content

Commit

Permalink
Merge pull request #2314 from telefonicaid/fix/mongo_index_error
Browse files Browse the repository at this point in the history
fix: reindex mongo error when datamodel change
  • Loading branch information
fgalan authored Oct 17, 2023
2 parents 9a040f4 + bb6b316 commit 81df32f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 81df32f

Please sign in to comment.