Skip to content

Set CosmosDbCollection

Daniel Scott-Raynsford edited this page May 31, 2022 · 6 revisions

external help file: CosmosDB-help.xml Module Name: CosmosDB online version: schema: 2.0.0

Set-CosmosDbCollection

SYNOPSIS

Update an existing collection in a Cosmos DB database.

SYNTAX

ContextIndexPolicy (Default)

Set-CosmosDbCollection -Context <Context> [-Key <SecureString>] [-KeyType <String>]
 [-Database <String>] -Id <String> [-IndexingPolicy <Policy>]
 [-DefaultTimeToLive <Int32>] [-RemoveDefaultTimeToLive] [-UniqueKeyPolicy <Policy>]
 [<CommonParameters>]

ContextIndexPolicyJson

Set-CosmosDbCollection -Context <Context> [-Key <SecureString>] [-KeyType <String>]
 [-Database <String>] -Id <String> [-IndexingPolicyJson <String>]
 [-DefaultTimeToLive <Int32>] [-RemoveDefaultTimeToLive] [-UniqueKeyPolicy <Policy>]
 [<CommonParameters>]

AccountIndexPolicyJson

Set-CosmosDbCollection -Account <String> [-Key <SecureString>] [-KeyType <String>]
 [-Database <String>] -Id <String> [-IndexingPolicyJson <String>]
 [-DefaultTimeToLive <Int32>] [-RemoveDefaultTimeToLive] [-UniqueKeyPolicy <Policy>]
 [<CommonParameters>]

AccountIndexPolicy

Set-CosmosDbCollection -Account <String> [-Key <SecureString>] [-KeyType <String>]
 [-Database <String>] -Id <String> [-IndexingPolicy <Policy>]
 [-DefaultTimeToLive <Int32>] [-RemoveDefaultTimeToLive] [-UniqueKeyPolicy <Policy>]
 [<CommonParameters>]

DESCRIPTION

This cmdlet will update an existing collection in a Cosmos DB. Only the indexing policy on a collection can be updated.

EXAMPLES

Example 1

PS C:\> $indexStringRange = New-CosmosDbCollectionIncludedPathIndex -Kind Range -DataType String -Precision -1
PS C:\> $indexNumberRange = New-CosmosDbCollectionIncludedPathIndex -Kind Range -DataType Number -Precision -1
PS C:\> $indexIncludedPath = New-CosmosDbCollectionIncludedPath -Path '/*' -Index $indexStringRange, $indexNumberRange
PS C:\> $newIndexingPolicy = New-CosmosDbCollectionIndexingPolicy -Automatic $true -IndexingMode Consistent -IncludedPath $indexIncludedPath
PS C:\> Set-CosmosDbCollection -Context $cosmosDbContext -Id 'MyExistingCollection' -IndexingPolicy $newIndexingPolicy

Update a collection in the database with the a new indexing policy.

Example 2

PS C:\> Set-CosmosDbCollection -Context $cosmosDbContext -Id 'MyExistingCollection' -DefaultTimeToLive 7200

Update a collection in the database with the a new default time to live of 7200 seconds.

Example 3

PS C:\> Set-CosmosDbCollection -Context $cosmosDbContext -Id 'MyExistingCollection' -RemoveDefaultTimeToLive

Update a collection in the database by removing the default time to live setting.

PARAMETERS

-Account

The account name of the Cosmos DB to access.

Type: String
Parameter Sets: AccountIndexPolicyJson, AccountIndexPolicy
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Context

This is an object containing the context information of the Cosmos DB database that will be deleted. It should be created by `New-CosmosDbContext`.

Type: Context
Parameter Sets: ContextIndexPolicy, ContextIndexPolicyJson
Aliases: Connection

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Database

The name of the database to access in the Cosmos DB account.

Type: String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-DefaultTimeToLive

Setting this value to a positive integer will enable the time to live on all documents in this collection. If this is set to -1 then the default time to live will be infinite.

Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Id

This is the Id of the collection to update.

Type: String
Parameter Sets: (All)
Aliases: Name

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-IndexingPolicy

This is an Indexing Policy object that was created by the Set-CosmosDbCollectionIndexingPolicy function. It should not be set if IndexingPolicyJson is set.

Type: Policy
Parameter Sets: ContextIndexPolicy, AccountIndexPolicy
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-IndexingPolicyJson

This is a JSON representation of an Indexing Policy. It should not be set if IndexingPolicy is set.

Type: String
Parameter Sets: ContextIndexPolicyJson, AccountIndexPolicyJson
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Key

The key to be used to access this Cosmos DB.

Type: SecureString
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-KeyType

The type of key that will be used to access ths Cosmos DB.

Type: String
Parameter Sets: (All)
Aliases:
Accepted values: master, resource

Required: False
Position: Named
Default value: Master
Accept pipeline input: False
Accept wildcard characters: False

-RemoveDefaultTimeToLive

If this switch is set then the default time to live setting on the collection will be removed if it is set. This switch should not be set if the DefaultTimeToLive parameter is specified.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-UniqueKeyPolicy

This is a Unique Key Policy object that was created by the New-CosmosDbCollectionUniquePolicy function.

Type: Policy
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

System.Object

NOTES

RELATED LINKS

CosmosDB Cmdlets

Clone this wiki locally