Пожалуйста, обратитесь к приведенным ниже сценариям 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
}
Подробнее, пожалуйста, обратитесь к этой статье .
Для нескольких учетных записей, пожалуйста, используйте следующий код:
$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'
}