简体   繁体   English

为什么我的 Azure Cosmos DB SQL API 容器拒绝具有相同分区键值的多个项目?

[英]Why does my Azure Cosmos DB SQL API Container Refuse Multiple Items With Same Partition Key Value?

In Azure Cosmos DB (SQL API) I've created a container whose "partition key" is set to /part_key and I am now trying to create and edit data in Data Explorer.在 Azure Cosmos DB (SQL API) 中,我创建了一个容器,其“分区键”设置为/part_key ,我现在正尝试在 Data Explorer 中创建和编辑数据。

I created an item that looks like this:我创建了一个看起来像这样的项目:

{
    "id": "test_id",
    "value": "val000",
    "magicNumber": 32,
    "part_key": "asdf"
}

I am now trying to create an item that looks like this:我现在正在尝试创建一个如下所示的项目:

{
    "id": "frank",
    "value": "val001",
    "magicNumber": 33,
    "part_key": "asdf"
}

Based on the documentation I believe that each item within a partition key needs a distinct id , which to me implies that multiple items can in fact share a partition key, which makes a lot of sense.根据文档,我认为分区键中的每个项目都需要一个不同的id ,这对我来说意味着多个项目实际上可以共享一个分区键,这很有意义。

However, I get an error when I try to save this second item:但是,当我尝试保存第二项时出现错误:

{"code":409,"body":{"code":"Conflict","message":"Entity with the specified id already exists in the system...

I see that if I change the value of part_key to something else (say asdf2 ), then I can save this new item.我看到如果我将part_key的值更改为其他值(比如asdf2 ),那么我可以保存这个新项目。

Either my expectations about this functionality are wrong, or else I'm doing this wrong somehow.要么我对这个功能的期望是错误的,要么我做错了。 What is wrong here?这里有什么问题?

Your understanding is correct, It could happen if you are trying to instead a new document with id equal to id of the existing document.您的理解是正确的,如果您尝试使用 id 等于现有文档的 id 的新文档,则可能会发生这种情况。 This is not allowed, so operation fails.这是不允许的,因此操作失败。

Before you insert the modified copy, you need to assign a new id to it.在插入修改后的副本之前,您需要为其分配一个新的 id。 I tested the scenario and it looks fine.我测试了这个场景,它看起来不错。 May be try to create a new document and check可能会尝试创建一个新文档并检查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM