我有一个ARM模板,用以下方式作为cosmosDb的primaryMasterKey来源:
{ "properties": { "enabled": true, "siteConfig": { "appSettings": [ { "name": "MongoDb:CnnDetails", "value": "[listKeys(resourceId('Microsoft.DocumentDB/databaseAccounts', variables('cosmosdb_full')), '2015-04-08').primaryMasterKey]" } }
如何修改它以获取实际的连接字符串?
我尝试了几件事情:
1.将单词primaryMasterKey更改为primaryConnectionString。这会出现错误,指出:“语言表达式属性'primaryConnectionString'不存在,可用属性为'primaryMasterKey、secondaryMasterKey、primaryReadonlyMasterKey、secondaryReadonlyMasterKey'”。
2.将work listKeys更改为listConnectionStrings。这在我的Visual Studio中是红色下划线,但在通过Azure DevOps时似乎有效。
“语言表达式属性'primaryConnectionString'不存在,可用属性为'connectionStrings'”。
我访问了https://learn.microsoft.com/en-us/rest/api/cosmos-db-resource-provider/databaseaccounts/listconnectionstrings#code-try-0来尝试它。ListKeys返回如下结构体: { "primaryMasterKey": "[REDACTED]", "secondaryMasterKey": "[REDACTED]", "primaryReadonlyMasterKey": "[REDACTED]", "secondaryReadonlyMasterKey": "[REDACTED]" } 因此,我明白为什么.primaryMasterKey有效。但是,ListConnectionStrings返回:
{ "properties": { "enabled": true, "siteConfig": { "appSettings": [ { "name": "MongoDb:CnnDetails", "value": "[listKeys(resourceId('Microsoft.DocumentDB/databaseAccounts', variables('cosmosdb_full')), '2015-04-08').primaryMasterKey]" } }
如何修改它以获取实际的连接字符串?
我尝试了几件事情:
1.将单词primaryMasterKey更改为primaryConnectionString。这会出现错误,指出:“语言表达式属性'primaryConnectionString'不存在,可用属性为'primaryMasterKey、secondaryMasterKey、primaryReadonlyMasterKey、secondaryReadonlyMasterKey'”。
2.将work listKeys更改为listConnectionStrings。这在我的Visual Studio中是红色下划线,但在通过Azure DevOps时似乎有效。
“语言表达式属性'primaryConnectionString'不存在,可用属性为'connectionStrings'”。
我访问了https://learn.microsoft.com/en-us/rest/api/cosmos-db-resource-provider/databaseaccounts/listconnectionstrings#code-try-0来尝试它。ListKeys返回如下结构体: { "primaryMasterKey": "[REDACTED]", "secondaryMasterKey": "[REDACTED]", "primaryReadonlyMasterKey": "[REDACTED]", "secondaryReadonlyMasterKey": "[REDACTED]" } 因此,我明白为什么.primaryMasterKey有效。但是,ListConnectionStrings返回:
{
"connectionStrings": [
{
"connectionString": "mongodb://[REDACTED]:10255/?ssl=true&replicaSet=globaldb",
"description": "Primary MongoDB Connection String"
},
{
"connectionString": "mongodb://[REDACTED]:10255/?ssl=true&replicaSet=globaldb",
"description": "Secondary MongoDB Connection String"
},
{
"connectionString": "mongodb://[REDACTED]:10255/?ssl=true&replicaSet=globaldb",
"description": "Primary Read-Only MongoDB Connection String"
},
{
"connectionString": "mongodb://[REDACTED]:10255/?ssl=true&replicaSet=globaldb",
"description": "Secondary Read-Only MongoDB Connection String"
}
]
}
不确定如何“索引到它”?
非常感谢任何线索。