Table of Contents

Class ContainerProperties

Namespace
Microsoft.Azure.Cosmos
Assembly
Microsoft.Azure.Cosmos.Client.dll

Represents a document container in the Azure Cosmos DB service. A container is a named logical container for documents.

public class ContainerProperties
Inheritance
ContainerProperties
Inherited Members
Extension Methods

Examples

The example below creates a new partitioned container with 50000 Request-per-Unit throughput. The partition key is the first level 'country' property in all the documents within this container.

Container container = await client.GetDatabase("dbName").Containers.CreateAsync("MyCollection", "/country", 50000);
ContainerProperties containerProperties = container.Resource;

The example below creates a new container with a custom indexing policy.

ContainerProperties containerProperties = new ContainerProperties("MyCollection", "/country");
containerProperties.IndexingPolicy.Automatic = true;
containerProperties.IndexingPolicy.IndexingMode = IndexingMode.Consistent;

CosmosContainerResponse containerCreateResponse = await client.GetDatabase("dbName").CreateContainerAsync(containerProperties, 50000);
ContainerProperties createdContainerProperties = containerCreateResponse.Container;

The example below deletes this container.

Container container = client.GetDatabase("dbName").Containers["MyCollection"];
await container.DeleteAsync();

Remarks

A database may contain zero or more named containers and each container consists of zero or more JSON documents. Being schema-free, the documents in a container do not need to share the same structure or fields. Since containers are application resources, they can be authorized using either the master key or resource keys.

Constructors

ContainerProperties()

Initializes a new instance of the ContainerProperties class for the Azure Cosmos DB service.

public ContainerProperties()
See Also

ContainerProperties(string, IReadOnlyList<string>)

Initializes a new instance of the ContainerProperties class for the Azure Cosmos DB service.

public ContainerProperties(string id, IReadOnlyList<string> partitionKeyPaths)

Parameters

id string

The Id of the resource in the Azure Cosmos service.

partitionKeyPaths IReadOnlyList<string>

The paths of the hierarchical partition keys. Example: ["/tenantId", "/userId"]

See Also

ContainerProperties(string, string)

Initializes a new instance of the ContainerProperties class for the Azure Cosmos DB service.

public ContainerProperties(string id, string partitionKeyPath)

Parameters

id string

The Id of the resource in the Azure Cosmos service.

partitionKeyPath string

The path to the partition key. Example: /location

See Also

Properties

AnalyticalStoreTimeToLiveInSeconds

Gets or sets the time to live for analytical store in seconds at container scope for the Azure Cosmos service.

Analytical store when enabled captures all the item changes in the container. AnalyticalStoreTimeToLiveInSeconds defines the time to live for the changes in analytical store.

public int? AnalyticalStoreTimeToLiveInSeconds { get; set; }

Property Value

int?

It is an optional property.

The unit of measurement is seconds. The maximum allowed value is 2147483647. A valid value must be either a nonzero positive integer, '-1' or null.

By default, AnalyticalStoreTimeToLiveInSeconds is set to null meaning analytical store is turned-off.

Examples

The example below disables analytical store on a container.

container.AnalyticalStoreTimeToLiveInSeconds = null;

The example below enables analytical store on container capturing all changes and never expire.

container.AnalyticalStoreTimeToLiveInSeconds = -1;

The example below enables analytical store on container capturing all changes and expire after 180days.

container.AnalyticalStoreTimeToLiveInSeconds = (int)TimeSpan.FromDays(6 * 30).TotalSeconds;

Remarks

The AnalyticalStoreTimeToLiveInSeconds is applicable to all the item changes in the container. It cannot be overriden or customizable per item.

When the AnalyticalStoreTimeToLiveInSeconds is null analytical store is turned-off. It means all the item changes in the container are disregarded.

When the AnalyticalStoreTimeToLiveInSeconds is '-1', all the items changes will be captured by analytical store and will never expire.

When the AnalyticalStoreTimeToLiveInSeconds is a nonzero positive integer, all the items changes will be captured by analytical store and expired after the specified time to live.

See Also

ClientEncryptionPolicy

Gets or sets the client encryption policy information for storing items in a container from the Azure Cosmos service.

public ClientEncryptionPolicy ClientEncryptionPolicy { get; set; }

Property Value

ClientEncryptionPolicy

It is an optional property. By default, ClientEncryptionPolicy is set to null meaning the feature is turned off for the container.

Remarks

The ClientEncryptionPolicy will be applied to all the items in the container as the default policy.

See Also

ConflictResolutionPolicy

Gets or sets the ConflictResolutionPolicy

public ConflictResolutionPolicy ConflictResolutionPolicy { get; set; }

Property Value

ConflictResolutionPolicy
See Also

DefaultTimeToLive

Gets or sets the default time to live in seconds for item in a container from the Azure Cosmos service.

public int? DefaultTimeToLive { get; set; }

Property Value

int?

It is an optional property.

The unit of measurement is seconds. The maximum allowed value is 2147483647. A valid value must be either a nonzero positive integer, '-1' or null.

By default, DefaultTimeToLive is set to null meaning the time to live is turned off for the container.

Examples

The example below disables time-to-live on a container.

container.DefaultTimeToLive = null;

The example below enables time-to-live on a container. By default, all the items never expire.

container.DefaultTimeToLive = -1;

The example below enables time-to-live on a container. By default, the item will expire after 1000 seconds since its last write time.

container.DefaultTimeToLive = 1000;

Remarks

The DefaultTimeToLive will be applied to all the items in the container as the default time-to-live policy. The individual item could override the default time-to-live policy by setting its time to live.

When the DefaultTimeToLive is null, the time-to-live will be turned off for the container. It means all the items will never expire. The individual item's time to live will be disregarded.

When the DefaultTimeToLive is '-1', the time-to-live will be turned on for the container. By default, all the items will never expire. The individual item could be given a specific time-to-live value by setting its time to live. The item's time to live will be honored, and the expired items will be deleted in background.

When the DefaultTimeToLive is a nonzero positive integer, the time-to-live will be turned on for the container. And a default time-to-live in seconds will be applied to all the items. A item will be expired after the specified DefaultTimeToLive value in seconds since its last write time.

See Also

ETag

Gets the entity tag associated with the resource from the Azure Cosmos DB service.

public string ETag { get; }

Property Value

string

The entity tag associated with the resource.

Remarks

ETags are used for concurrency checking when updating resources.

See Also

GeospatialConfig

Gets the GeospatialConfig associated with the collection from the Azure Cosmos DB service.

public GeospatialConfig GeospatialConfig { get; set; }

Property Value

GeospatialConfig

Geospatial type of collection i.e. geography or geometry

See Also

Id

Gets or sets the Id of the resource in the Azure Cosmos DB service.

public string Id { get; set; }

Property Value

string

The Id associated with the resource.

Remarks

Every resource within an Azure Cosmos DB database account needs to have a unique identifier. Unlike Microsoft.Azure.Documents.Resource.ResourceId, which is set internally, this Id is settable by the user and is not immutable.

The following characters are restricted and cannot be used in the Id property: '/', '\\', '?', '#'

See Also

IndexingPolicy

Gets the IndexingPolicy associated with the container from the Azure Cosmos DB service.

public IndexingPolicy IndexingPolicy { get; set; }

Property Value

IndexingPolicy

The indexing policy associated with the container.

See Also

LastModified

Gets the last modified time stamp associated with ContainerProperties from the Azure Cosmos DB service.

public DateTime? LastModified { get; }

Property Value

DateTime?

The last modified time stamp associated with the resource.

See Also

PartitionKeyDefinitionVersion

Gets or sets the PartitionKeyDefinitionVersion

The partition key definition version 1 uses a hash function that computes hash based on the first 100 bytes of the partition key. This can cause conflicts for documents with partition keys greater than 100 bytes.

The partition key definition version 2 uses a hash function that computes hash based on the first 2 KB of the partition key.

public PartitionKeyDefinitionVersion? PartitionKeyDefinitionVersion { get; set; }

Property Value

PartitionKeyDefinitionVersion?

The Partition Key Definition Version of the container

See Also

PartitionKeyPath

JSON path used for containers partitioning

public string PartitionKeyPath { get; set; }

Property Value

string
See Also

PartitionKeyPaths

List of JSON paths used for containers with hierarchical partition keys

public IReadOnlyList<string> PartitionKeyPaths { get; set; }

Property Value

IReadOnlyList<string>
See Also

Gets the self-link associated with the resource from the Azure Cosmos DB service.

public string SelfLink { get; }

Property Value

string

The self-link associated with the resource.

A self-link is a static addressable Uri for each resource within a database account and follows the Azure Cosmos DB resource model. E.g. a self-link for a document could be dbs/db_resourceid/colls/coll_resourceid/documents/doc_resourceid

See Also

TimeToLivePropertyPath

Gets or sets the time to live base time stamp property path.

[Obsolete]
public string TimeToLivePropertyPath { get; set; }

Property Value

string

It is an optional property. This property should be only present when DefaultTimeToLive is set. When this property is present, time to live for a item is decided based on the value of this property in item. By default, TimeToLivePropertyPath is set to null meaning the time to live is based on the _ts property in item.

See Also

UniqueKeyPolicy

Gets or sets the UniqueKeyPolicy that guarantees uniqueness of documents in container in the Azure Cosmos DB service.

public UniqueKeyPolicy UniqueKeyPolicy { get; set; }

Property Value

UniqueKeyPolicy
See Also

See Also