如何使用 CLI 创建分区的 Azure MongoDB 集合?

How to create a partitioned Azure MongoDB collection with the CLI?

az cosmosdb collection create 的 Microsoft 文档 表示 --partition-key-path 可用于命名用于集合的键。在本例中,它是一个 "MongoDB" 集合:

name='myName'
databaseName='myDatabase'
resourceGroupName='myRg'
collectionName='myCollection'

echo "Create database account"
az cosmosdb create --name $name --kind MongoDB --locations "Central US"=0 --resource-group $resourceGroupName

echo "Create database"
az cosmosdb database create --name $name --db-name $databaseName --resource-group $resourceGroupName

echo "Create collection $collectionName"
az cosmosdb collection create --name $name --db-name $databaseName --resource-group $resourceGroupName --collection-name $collectionName --partition-key-path '/partition'

我需要更改什么才能避免以下错误并创建分区集合?

Create database account
...
Create database
...
Create collection myCollection
ERROR: Operation Failed: Invalid Arg {"Errors":["The partition key component definition path
'C:\/Apps\/Git\/partition' could not be accepted, failed near position '0'. Partition key paths must contain only
valid characters and not contain a trailing slash or wildcard character."]}

所以在所有来回之后它似乎是一个路径转义问题,其中分区键,当提供单引号时,被假定为来自 bash.

的文件夹

然而,将单引号更改为双引号有效。

当尝试 运行 和 cmd /C 时,以下似乎有效。

cmd "/C az cosmosdb collection create --name $name --db-name $databaseName --resource-group $resourceGroupName --collection-name $collectionName --partition-key-path "/partition""