在 CosmosDB 上创建唯一索引错误 (Mongo API)
Create unique index error on CosmosDB (Mongo API)
我正在尝试为我们的 CosmosDB 上的某些集合创建唯一索引。 Per MS document https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-indexing : 只有当集合为空(不包含文档)时才能创建唯一索引。
所以我清理了集合中的所有数据,但是我遇到了错误,消息是:
Error=13, Details='响应状态码不表示成功:Forbidden (403);子状态: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,请求 URI:/apps/xxx/xxx/partitions/xxx/replicas/xx,RequestStats:
RequestStartTime:2020-12-02T23:25:04.2104773Z,RequestEndTime:2020-12-02T23:25:04.2204125Z,区域数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, 请参阅 CosmosDiagnostics, Windows/10.0.17763 cosmos-netstandard-sdk/3.3.2);
然后我尝试只添加字段名称,然后抛出如下错误:
当集合包含文档时无法创建唯一索引
我们正在使用支持 Mongodb 3.6 的 CosomosDB。我正在使用命令:
db.CollectName.createIndex({“字段名”:1},{“唯一”:真})
知道我为什么会收到这些错误吗?
谢谢,
不确定发生了什么,但它现在突然开始工作了。所以步骤是清理集合中的数据。 运行 添加唯一索引然后加载数据的脚本。我正在使用 Robo 3t 连接到 CosmosDB 并通过 Robo3T 命令行 运行 所有命令。
我正在尝试为我们的 CosmosDB 上的某些集合创建唯一索引。 Per MS document https://docs.microsoft.com/en-us/azure/cosmos-db/mongodb-indexing : 只有当集合为空(不包含文档)时才能创建唯一索引。
所以我清理了集合中的所有数据,但是我遇到了错误,消息是:
Error=13, Details='响应状态码不表示成功:Forbidden (403);子状态: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,请求 URI:/apps/xxx/xxx/partitions/xxx/replicas/xx,RequestStats: RequestStartTime:2020-12-02T23:25:04.2104773Z,RequestEndTime:2020-12-02T23:25:04.2204125Z,区域数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, 请参阅 CosmosDiagnostics, Windows/10.0.17763 cosmos-netstandard-sdk/3.3.2);
然后我尝试只添加字段名称,然后抛出如下错误:
当集合包含文档时无法创建唯一索引
我们正在使用支持 Mongodb 3.6 的 CosomosDB。我正在使用命令: db.CollectName.createIndex({“字段名”:1},{“唯一”:真})
知道我为什么会收到这些错误吗?
谢谢,
不确定发生了什么,但它现在突然开始工作了。所以步骤是清理集合中的数据。 运行 添加唯一索引然后加载数据的脚本。我正在使用 Robo 3t 连接到 CosmosDB 并通过 Robo3T 命令行 运行 所有命令。