【问题标题】:Insert document in Cosmos DB using PowerShell (SQL API) using azure Devops CLI Task使用 PowerShell (SQL API) 使用 azure Devops CLI 任务在 Cosmos DB 中插入文档
【发布时间】:2022-07-22 16:35:12
【问题描述】:

源代码:


$resourceGroupName = 'rg-****'
$accountName = 'cosmosserver-****'
$databaseName = 'DefaultSystemDB'
$OrganisationName = "SampleOrg"
$ContractName = 'SampleContract'
$TypeName = 'SampleType"
$currentDate = Get-Date -Format 'yyyy-MM-dd HH:mm:ss
write-Host $currentDate    
$containerName = 'Organisation'
$partitionKey = '/id'
$cosmosDbContext = New-CosmosDbContext -Account $accountName -Database $databaseName -ResourceGroup $resourceGroupName
$Organisationid='$([Guid]::NewGuid().ToString())'
write-Host Organisationid: $Organisationid    
$document = @"
{
        "Name": '$OrganisationName',       
        "CreatedOn": '$currentDate',
        "id":  '$Organisationid'
}
"@
$partitionkey = '$Organisationid'
New-CosmosDbDocument -Context $cosmosDbContext -CollectionId $containerName -DocumentBody $document -PartitionKey $partitionkey

问题:


我在 azuredevops 的 azureCLI 任务中执行上述代码时收到以下错误 错误: New-CosmosDbContext : 术语“New-CosmosDbContext”未被识别为 cmdlet 的名称,

解决此问题或使用 AzureDevops 中的 azure CLI 任务在 cosmosDB 容器中插入文档的任何其他建议的步骤是什么?请帮我找出这个问题。

【问题讨论】:

    标签: azure-devops


    【解决方案1】:

    请先安装 CosmosDB 模块。默认情况下,该模块不在托管代理中。请在脚本的开头添加以下内容。安装它可能需要几分钟时间。

    Install-Module -Name CosmosDB -force
    

    【讨论】:

      猜你喜欢
      • 2019-01-23
      • 1970-01-01
      • 1970-01-01
      • 2018-03-02
      • 2020-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多