liquibase-mongodb
liquibase-mongodb copied to clipboard
Azure (Cosmos DB API for MongoDB) - index missing
After running liquibase with option liquibase.mongodb.supportsValidator=false
(too avoid issue #235 ) on Azure - Cosmos DB API for MongoDB, we received this error :
...
Caused by: liquibase.exception.DatabaseException: Could not query for list
at liquibase.nosql.executor.NoSqlExecutor.queryForList(NoSqlExecutor.java:145)
at liquibase.nosql.executor.NoSqlExecutor.queryForList(NoSqlExecutor.java:135)
at liquibase.ext.mongodb.changelog.MongoHistoryService.queryRanChangeSets(MongoHistoryService.java:138)
at liquibase.nosql.changelog.AbstractNoSqlHistoryService.getRanChangeSets(AbstractNoSqlHistoryService.java:158)
at liquibase.changelog.AbstractChangeLogHistoryService.upgradeChecksums(AbstractChangeLogHistoryService.java:73)
at liquibase.command.core.helpers.DatabaseChangelogCommandStep.checkLiquibaseTables(DatabaseChangelogCommandStep.java:143)
at liquibase.command.core.helpers.DatabaseChangelogCommandStep.run(DatabaseChangelogCommandStep.java:91)
at liquibase.command.CommandScope.execute(CommandScope.java:214)
... 23 more
Caused by: com.mongodb.MongoQueryException: Command failed with error 2 (BadValue): 'Error=2, Details='Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: c7f9383e-1bce-4ca5-b0fa-63c3a0e3f3b0; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: c7f9383e-1bce-4ca5-b0fa-63c3a0e3f3b0; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 0; ActivityId: c7f9383e-1bce-4ca5-b0fa-63c3a0e3f3b0;
Reason: (Message: {"Errors":["The index path corresponding to the specified order-by item is excluded."]}
Apparently, on cosmosdb, all field present in sort option should be indexed (see error 2 in https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/error-codes-solutions )
My workaround is to create indexes before the 1st run of liquibase :
//original index from liquibase-mongodb {"fileName": new NumberInt("1"), "author": new NumberInt("1"), "id": new NumberInt("1")}
db.DATABASECHANGELOG.createIndex({fileName: 1, author: 1, id: 1}, {name: "ui_DATABASECHANGELOG", unique: true});
//new index (mandatory for cosmosDB)
db.DATABASECHANGELOG.createIndex({orderExecuted: 1}, {name: "i_DATABASECHANGELOG_orderExecuted"});
//new index (mandatory for cosmosDB)
db.DATABASECHANGELOG.createIndex({dateExecuted: 1}, {name: "i_DATABASECHANGELOG_dateExecuted"});