I'm getting an error when I am trying to insert data in Cosmos DB collection having Partition Key.
Without Partition key, it's working fine
$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": This is my Partition Key
Invoke-WebRequest : The remote server returned an error: (400) Bad Request. At 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
Anyone know about this??
$document
as String? You could just useConvertTo-Json
. It helps you to ensure, your json is valid. – Clijsters