Azure cosmosdb 删除并重新创建具有不同分区密钥的Cosmos DB容器。。。使用相同的分区键创建

Azure cosmosdb 删除并重新创建具有不同分区密钥的Cosmos DB容器。。。使用相同的分区键创建,azure-cosmosdb,Azure Cosmosdb,我在Cosmos DB中有一个笔记本,我正在尝试删除和创建几个容器 我们有各种各样的环境,无法访问Live,所以我需要这个脚本来完成所有工作 我有以下容器(和分区键) 续(第一部分) 续(第二部分) 续(第三部分) 我知道我不能更改分区键,所以我想删除容器并用一个新的分区键创建以下内容 续(第四部分) 续(第四部分) 续(第四部分) 我使用下面的代码来实现这一点 from azure.cosmos.partition_key import PartitionKey # Create new d

我在Cosmos DB中有一个笔记本,我正在尝试删除和创建几个容器

我们有各种各样的环境,无法访问Live,所以我需要这个脚本来完成所有工作

我有以下容器(和分区键)

续(第一部分)

续(第二部分)

续(第三部分)

我知道我不能更改分区键,所以我想删除容器并用一个新的分区键创建以下内容

续(第四部分)

续(第四部分)

续(第四部分)

我使用下面的代码来实现这一点

from azure.cosmos.partition_key import PartitionKey

# Create new database
database = cosmos_client.get_database_client("MyCosmosDB")

# FIRST SCRIPT
# Get a list of all current containers and if there are any, 
# iterate through and delete them all
containers = list(database.list_containers())
if containers:
    for container in containers:        
        print("Deleting the " + container['id'] + " container...")
        try:                   
            database.delete_container(container['id'])           
        except errors.CosmosHttpResponseError as e:
            raise
else:
    print("Ther are no containers in container to delete in this database")

# SECOND SCRIPT
# Create containers
ContAContainer = database.create_container(id='ContA', partition_key=PartitionKey(path='/part4'))
print("Creating ContA container...\n")
ContBContainer = database.create_container(id='ContB', partition_key=PartitionKey(path='/part4'))
print("Creating ContB container...\n")
ContCContainer = database.create_container(id='ContC', partition_key=PartitionKey(path='/part4'))
print("Creating ContC container...\n")

问题: 如果我分别运行第一个脚本和第二个脚本,一切都很好。 如果我运行这个脚本的第一部分(删除),这会很好地删除容器

如果我运行这个脚本的第二部分(creates),这将使用part4分区键很好地创建它们

但是有了旧的容器,当我像上面一样将它们一起运行时,容器保留了它们原来的分区键。。。所以ContA仍然将part1作为它的分区键,而不是第二个脚本中定义的part4


有谁能告诉我这里发生了什么,以及我如何使用这个脚本中的正确分区键创建容器。

我已经尝试了您的代码

但当我把旧容器放在一起时 上面,容器保留了它们原来的分区键。。。那么康塔 仍然将part1作为其分区键,而不是中定义的part4# 第二个脚本


这似乎是一个显示错误。在我执行notebook之后,我点击了刷新树按钮,它仍然显示了原始的分区键(“/part1”、“/part2”、“/part3”),如您所述。但当我刷新浏览器页面时,分区键将为“/part4”。

谢谢史蒂夫。。。这是我应该努力做到公平的事情。。。我被刷新按钮愚弄了!!再次感谢:)