Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure (Cosmos DB API for MongoDB) - index missing #493

Open
Vinss26 opened this issue Jan 26, 2024 · 0 comments
Open

Azure (Cosmos DB API for MongoDB) - index missing #493

Vinss26 opened this issue Jan 26, 2024 · 0 comments

Comments

@Vinss26
Copy link

Vinss26 commented Jan 26, 2024

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"});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant