请参阅以下PowerShell脚本以在Cosmos数据库中创建带有数据库的集合:
$primaryKey = ConvertTo-SecureString -String '<your connectString>' -AsPlainText -Force
$cosmosDbContext = New-CosmosDbContext -Account 'jaygongcosmos' -Database 'db' -Key $primaryKey
New-CosmosDbCollection -Context $cosmosDbContext -Id 'MyNewCollection' -OfferThroughput 2500
关于插入虚拟文档:
0..9 | Foreach-Object {
$document = @"
{
`"id`": `"$([Guid]::NewGuid().ToString())`",
`"content`": `"Some string`",
`"more`": `"Some other string`"
}
"@
New-CosmosDbDocument -Context $cosmosDbContext -CollectionId 'MyNewCollection' -DocumentBody $document
}
详情请参阅
article
.
对于多个帐户,请使用以下代码:
$array= '<your cosmos db account name>',.......
foreach($item in $array){
$key = Get-CosmosDbAccountMasterKey -Name $item -ResourceGroupName 'jaygong'
$cosmosDbContext = New-CosmosDbContext -Account $item -Key $key
New-CosmosDbCollection -Context $cosmosDbContext -Id 'Mytest1' -OfferThroughput 2500 -Database 'db'
}