使用PowerShell(SQL API)在Cosmos DB中插入文档 [英] Insert document in Cosmos DB using PowerShell (SQL API)

查看:101
本文介绍了使用PowerShell(SQL API)在Cosmos DB中插入文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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    

$document = @"
{
        "id": "6fa9b3d5-ce1a-4b38-9068-9d17de5b1c69",
        "createTime": "2018-05-21T22:59:59.999Z",
        "RuleType": "FTOD"
    }

"@
New-CosmosDbDocument -Context $cosmosDbContext -CollectionId 'events' - 
DocumentBody $document

"RuleType" ;:这是我的分区密钥

Invoke-WebRequest:远程服务器返回错误:(400)错误的请求.在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

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

请帮助我解决此问题.

Please help me to resolve this issue.

推荐答案

PankajRawat,

Hi PankajRawat,

您要与Azure Cosmos数据库实例一起使用哪个API?我找不到与文档创建有关的Powershell cmdlet,以及与Cosmos DB一起使用的Powershell模块.我正在将CosmosDB 2.1.5.548显示为最新版本:

Which API are you using with your Azure Cosmos DB instance? I am not finding Powershell cmdlets pertaining to the creation of documents and which Powershell module are you using for Cosmos DB. I am showing CosmosDB 2.1.5.548 as being the latest:

PS C:\ WINDOWS \ system32> New-CosmosDbDocument-?
PS C:\WINDOWS\system32> New-CosmosDbDocument -?


这篇关于使用PowerShell(SQL API)在Cosmos DB中插入文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆