Reputation: 11
I am using Axon framework with MongoEventStorgeEngine with CosmosDB for Mongo API.
Azure Cosmos DB for MongoDB accounts with continuous backup do not support creating a unique index for an existing collection. For such an account, unique indexes must be created along with their collection; this is done using the create collection extension commands
I am trying below options but could not get over Index creation error.
ensureIndexes - New version, does not support ensureIndexes with boolean false. I tried to override ensureIndexes method by extending DocumentPerEventStorageStrategy class but getting into other issues.
tried to have custom StorageStrategy or use MongoTemple to createIndexes using below code but was getting unauthorized or index already exists error
Code snippet
eventsCollection.createIndex(
Indexes.ascending("aggregateIdentifier", "sequenceNumber"),
new IndexOptions().unique(true).name("uniqueAggregateIndex"));
eventsCollection.createIndex(
Indexes.ascending("timestamp", "sequenceNumber"),
new IndexOptions().unique(true).name("orderedEventStreamIndex"));
Error log
(Message: {"Errors":["The unique index cannot be modified. To change the unique index, remove the collection and re-create a new one."]}
...
OperationType: Replace\r\n, SDK: Microsoft.Azure.Documents.Common/2.14.0, Microsoft.Azure.Cosmos.Tracing.TraceData.ClientSideRequestStatisticsTraceDatum, Windows/10.0.20348 cosmos-netstandard-sdk/3.18.0);", "code": 13, "codeName": "Unauthorized"}
Anyone using Cosmos DB for Mongo with continuous backup option (or others), please help
Upvotes: 1
Views: 61
Reputation: 401
Seems like you should be able to work around the problem by having a custom storage strategy. Please be aware that using the Mongo api for the event store can have some other challenges as well, as can be read here. So it might be a good moment to think about migrating the event store.
Upvotes: 1