【发布时间】:2019-01-23 07:54:50
【问题描述】:
当我尝试在具有分区键的 Cosmos DB 集合中插入数据时出现错误。
没有分区键,它工作正常
$resourceGroupName = "myrg"
$cosmosDbAccountName = "mydb"
$databaseName = "test"
$cosmosDbContext = New-CosmosDbContext -Account $cosmosDbAccountName -
Database $databaseName -ResourceGroup $resourceGroupName
New-CosmosDbCollection -Context $cosmosDbContext -Id 'events' -OfferThroughput 1000 -PartitionKey 'RuleType' -DefaultTimeToLive 604800
$document = @"
{
"id": "$([Guid]::NewGuid().ToString())",
"createTime": "2018-05-21T22:59:59.999Z",
"RuleType": "FTOD"
}
"@
New-CosmosDbDocument -Context $cosmosDbContext -CollectionId 'events' -
DocumentBody $document -PartitionKey 'RuleType'
“RuleType”:这是我的分区键
Invoke-WebRequest :远程服务器返回错误:(400) Bad Request。 在 C:\Program Files\WindowsPowerShell\Modules\CosmosDB\2.1.4.536\lib\utils.ps1:554 char:30 + ... estResult = Invoke-WebRequest -UseBasicParsing @invokeWebRequestParam ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
有人知道吗?
【问题讨论】:
-
我真的建议您将错误消息添加为文本,而不是图像。它使阅读、复制、评估、搜索等变得更容易
-
为什么将
$document实例化为字符串?你可以使用ConvertTo-Json。它可以帮助您确保您的 json 是有效的。 -
好建议!没有任何具体原因。