I am trying to create an unique index on some of the collections on our CosmosDB. Per MS document https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-indexing : Unique indexes can be created only when the collection is empty (contains no documents).
So I cleanup all the data on the collection, however I was encountering the error, the message was :
Error=13, Details='Response status code does not indicate success: Forbidden (403); Substatus: 0; ActivityId: xxx, Reason: (Message: {"serializedCollection":"{"Errors":["The unique index cannot be modified. To change the unique index, remove the collection and re-create a new one."]}","serializedOffer":"","serializedPartitionKeyRanges":[],"serializedPartitions":[],"collectionRemoteStorageSecurityIdentifier":"xxx","collectionChildResourceNameLimitInBytes":-1,"collectionChildResourceContentLengthLimitInKB":-1,"uniqueIndexNameEncodingMode":0,"uniqueIndexReIndexingState":0} ActivityId: xxx, Request URI: /apps/xxx/xxx/partitions/xxx/replicas/xx, RequestStats: RequestStartTime: 2020-12-02T23:25:04.2104773Z, RequestEndTime: 2020-12-02T23:25:04.2204125Z, Number of regions attempted:1 ResponseTime: 2020-12-02T23:25:04.2204125Z, StoreResult: StorePhysicalAddress: rntbd://10.0.0.29:11000/apps/xxx/services/xx/partitions/xx/replicas/xx, LSN: 41, GlobalCommittedLsn: 41, PartitionKeyRangeId: , IsValid: True, StatusCode: 403, SubStatusCode: 0, RequestCharge: 1.57, ItemLSN: -1, SessionToken: -1#41, UsingLocalLSN: False, TransportException: null, ResourceType: Collection, OperationType: Replace , SDK: Microsoft.Azure.Documents.Common/2.11.0, Please see CosmosDiagnostics, Windows/10.0.17763 cosmos-netstandard-sdk/3.3.2);
I then tried to add only the field name , then it was throwing errors like:
Cannot create unique index when collection contains documents
We are using CosomosDB which supports Mongodb 3.6. I was using the command: db.CollectName.createIndex({"fieldname" : 1}, {"unique" : true } )
Any ideas why I am getting the errors?
Thanks,