Azure Azure PowerShell Documentation

AzCosmosDBCollection

Synopsis

Creates a new Azure Cosmos DB collection (container) within an existing database.

Syntax

New-AzCosmosDBCollection
    -ResourceGroupName <String>
    -AccountName <String>
    -DatabaseName <String>
    -Name <String>
    [-PartitionKeyPath <String>]
    [-Throughput <Int32>]
    [-IndexingPolicy <Hashtable>]
    [-DefaultTimeToLive <Int64>]
    [-Location <String>]
    [-WhatIf]
    [-Confirm]

Parameters

ParameterTypeRequiredDescription
-ResourceGroupNameStringYesName of the resource group containing the Cosmos DB account.
-AccountNameStringYesName of the Cosmos DB account.
-DatabaseNameStringYesExisting database where the collection will be created.
-NameStringYesName of the new collection (container).
-PartitionKeyPathStringNoPath of the partition key (e.g., /myPartitionKey).
-ThroughputInt32NoProvisioned throughput (RU/s). Default is 400.
-IndexingPolicyHashtableNoCustom indexing policy definition.
-DefaultTimeToLiveInt64NoTTL in seconds for items; -1 disables TTL.
-LocationStringNoAzure region for the collection (overrides account default).
-WhatIfSwitchParameterNoShows what would happen if the command runs.
-ConfirmSwitchParameterNoPrompts for confirmation before executing.

Examples

Example 1: Create a collection with default settings

New-AzCosmosDBCollection `
  -ResourceGroupName "MyResourceGroup" `
  -AccountName "mycosmosdbaccount" `
  -DatabaseName "myDatabase" `
  -Name "myContainer"

Example 2: Create a collection with a custom partition key and throughput

New-AzCosmosDBCollection `
  -ResourceGroupName "RG1" `
  -AccountName "cosmosacct" `
  -DatabaseName "OrdersDB" `
  -Name "Orders" `
  -PartitionKeyPath "/orderId" `
  -Throughput 1000

Example 3: Create a collection with TTL enabled (30 days)

New-AzCosmosDBCollection `
  -ResourceGroupName "RG1" `
  -AccountName "cosmosacct" `
  -DatabaseName "LogsDB" `
  -Name "AppLogs" `
  -PartitionKeyPath "/logType" `
  -DefaultTimeToLive 2592000

Related Cmdlets