azure - 为什么设置 CosmosDB ThroughputSettings 会导致 "Entity with the specified id does not exist in the system"?

标签 azure azure-cosmosdb azure-resource-manager azure-rm-template

在尝试部署具有 2 个集合(“MyCollection1”、“MyCollection2”)的 CosmosDB 实例时,我不断收到错误:

NotFound: Entity with the specified id does not exist in the system

所以我一直在我的自定义 ARM 模板中搜索“resourceId”(请参见下文),但找不到错误原因。

我不明白,为什么管道至少不为我打印行号?

pipeline screenshot

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "accountName": {
            "defaultValue": "my-cosmosdb",
            "type": "String"
        }
    },
    "variables": {
        "resourceName": "[concat(resourceGroup().name, '-', parameters('accountName'))]",
        "resourceId": "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('resourceName'))]",
        "apiVersion": "[providers('Microsoft.DocumentDB', 'databaseAccounts').apiVersions[0]]"
    },
    "outputs": {
        "CosmosDbConnectionString": {
            "type": "string",
            "value": "[concat('AccountEndpoint=https://', variables('resourceName'), '.documents.azure.com:443/;AccountKey=', listKeys(variables('resourceId'), variables('apiVersion')).primaryMasterKey, ';')]"
        },
        "DatabaseName": {
            "type": "string",
            "value": "MyDB"
        },
        "CollectionName1": {
            "type": "string",
            "value": "MyCollection1"
        },
        "CollectionName2": {
            "type": "string",
            "value": "MyCollection2"
        }
    },
    "resources": [
        {
            "type": "Microsoft.DocumentDB/databaseAccounts",
            "apiVersion": "2020-03-01",
            "name": "[variables('resourceName')]",
            "location": "[resourceGroup().location]",
            "tags": {
                "defaultExperience": "DocumentDB"
            },
            "kind": "GlobalDocumentDB",
            "properties": {
                "publicNetworkAccess": "Enabled",
                "enableAutomaticFailover": false,
                "enableMultipleWriteLocations": false,
                "isVirtualNetworkFilterEnabled": false,
                "virtualNetworkRules": [],
                "disableKeyBasedMetadataWriteAccess": false,
                "databaseAccountOfferType": "Standard",
                "consistencyPolicy": {
                    "defaultConsistencyLevel": "Session",
                    "maxIntervalInSeconds": 5,
                    "maxStalenessPrefix": 100
                },
                "locations": [
                    {
                        "locationName": "[resourceGroup().location]",
                        "provisioningState": "Succeeded",
                        "failoverPriority": 0,
                        "isZoneRedundant": false
                    }
                ],
                "capabilities": []
            }
        },
        {
            "type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases",
            "apiVersion": "2020-03-01",
            "name": "[concat(variables('resourceName'), '/MyDB')]",
            "dependsOn": [
                "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('resourceName'))]"
            ],
            "properties": {
                "resource": {
                    "id": "MyDB"
                },
                "options": {}
            }
        },
        {
            "type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers",
            "apiVersion": "2020-03-01",
            "name": "[concat(variables('resourceName'), '/MyDB/MyCollection1')]",
            "dependsOn": [
                "[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlDatabases', variables('resourceName'), 'MyDB')]",
                "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('resourceName'))]"
            ],
            "properties": {
                "resource": {
                    "id": "MyCollection1",
                    "indexingPolicy": {
                        "indexingMode": "consistent",
                        "automatic": true,
                        "includedPaths": [
                            {
                                "path": "/*"
                            }
                        ],
                        "excludedPaths": [
                            {
                                "path": "/\"_etag\"/?"
                            }
                        ]
                    },
                    "partitionKey": {
                        "paths": [
                            "/partitionKey"
                        ],
                        "kind": "Hash"
                    },
                    "uniqueKeyPolicy": {
                        "uniqueKeys": []
                    },
                    "conflictResolutionPolicy": {
                        "mode": "LastWriterWins",
                        "conflictResolutionPath": "/_ts"
                    }
                },
                "options": {}
            }
        },
        {
            "type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers",
            "apiVersion": "2020-03-01",
            "name": "[concat(variables('resourceName'), '/MyDB/MyCollection2')]",
            "dependsOn": [
                "[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlDatabases', variables('resourceName'), 'MyDB')]",
                "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('resourceName'))]"
            ],
            "properties": {
                "resource": {
                    "id": "MyCollection2",
                    "indexingPolicy": {
                        "indexingMode": "consistent",
                        "automatic": true,
                        "includedPaths": [
                            {
                                "path": "/*"
                            }
                        ],
                        "excludedPaths": [
                            {
                                "path": "/\"_etag\"/?"
                            }
                        ]
                    },
                    "partitionKey": {
                        "paths": [
                            "/partitionKey"
                        ],
                        "kind": "Hash"
                    },
                    "uniqueKeyPolicy": {
                        "uniqueKeys": []
                    },
                    "conflictResolutionPolicy": {
                        "mode": "LastWriterWins",
                        "conflictResolutionPath": "/_ts"
                    }
                },
                "options": {}
            }
        },
        {
            "type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/throughputSettings",
            "apiVersion": "2020-03-01",
            "name": "[concat(variables('resourceName'), '/MyDB/default')]",
            "dependsOn": [
                "[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlDatabases', variables('resourceName'), 'MyDB')]",
                "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('resourceName'))]"
            ],
            "properties": {
                "resource": {
                    "throughput": 400
                }
            }
        }
    ]
}

更新:

我已经删除了创建集合的部分,但错误仍然存​​在。

更新2:

以下部分似乎会导致错误,但为什么呢?

{
    "type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases/throughputSettings",
    "apiVersion": "2020-03-01",
    "name": "[concat(variables('resourceName'), '/MyDB/default')]",
    "dependsOn": [
        "[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlDatabases', variables('resourceName'), 'MyDB')]",
        "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('resourceName'))]"
    ],
    "properties": {
        "resource": {
            "throughput": 400
        }
    }
}

dependsOn 条目有什么问题"[resourceId('Microsoft.DocumentDB/databaseAccounts/sqlDatabases', Variables('resourceName'), 'MyDB')]

更新3:

尝试手动部署上面列出的完整 ARM 模板会导致:

screenshot throughput error

screenshot error

最佳答案

尝试在数据库选项中设置吞吐量。

更新:您无法在最初配置时没有吞吐量的资源上指定吞吐量。没有吞吐量配置的数据库和容器稍后无法更新以拥有吞吐量。相反,配置有吞吐量的资源无法更新或删除。您必须删除并重新创建资源。这将需要迁移您的数据。

{
        "type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases",
        "apiVersion": "2020-03-01",
        "name": "[concat(variables('resourceName'), '/MyDB')]",
        "dependsOn": [
            "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('resourceName'))]"
        ],
        "properties": {
            "resource": {
                "id": "MyDB"
            },
            "options": { "throughput": "[parameters('throughput')]" }
        }
    },

顺便说一句,这里有很多示例可以用来开始 Cosmos DB templates

关于azure - 为什么设置 CosmosDB ThroughputSettings 会导致 "Entity with the specified id does not exist in the system"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61698736/

相关文章:

c# - 无法解析属性 'CosmosDBAttribute.ConnectionStringSetting' 的值

Azure ARM 模板 SQL Azure 数据库 Bacpac 导入在第二次部署时失败

json - Azure Bicep/Json - 无法正确解析 JSON

Azure Cosmos DB 函数 - 删除文档

python - Azure函数使用ssh访问私有(private)github存储库

c# - 当托管在 Azure 应用服务中时,如何控制添加到 ASP.NET Core Web 应用程序的 HTTP 响应 header ?

azure - 在 Azure 门户上找不到 EduRoster 权限

Azure Cosmos Db 模拟器已启动但从未启动

azure - 在azure门户中创建调度程序时出现"Can not find subscription"错误

c# - csv 文件导入 Azure 存储时出现数据格式问题