DocumentCollection Class
Updated: June 30, 2017
Represents a document collection in the Azure DocumentDB database service. A collection is a named logical container for documents.
Assembly: Microsoft.Azure.Documents.Client (in Microsoft.Azure.Documents.Client.dll)
Microsoft.Azure.DocumentsJsonSerializable
Microsoft.Azure.DocumentsResource
Microsoft.Azure.DocumentsDocumentCollection
| Name | Description | |
|---|---|---|
![]() | DocumentCollection | Initializes a new instance of the DocumentCollection class for the Azure DocumentDB database service. |
| Name | Description | |
|---|---|---|
![]() | Gets the alt-link associated with the resource from the Azure DocumentDB database service. (Inherited from Resource.) | |
![]() | Gets the self-link for conflicts in a collection from the Azure DocumentDB database service. | |
![]() | Gets the default time to live in seconds for documents in a collection from the Azure DocumentDB database service. | |
![]() | Gets the self-link for documents in a collection from the Azure DocumentDB database service. | |
![]() | Gets the entity tag associated with the resource from the Azure DocumentDB database service. (Inherited from Resource.) | |
![]() | Gets or sets the Id of the resource in the Azure DocumentDB database service. (Inherited from Resource.) | |
![]() | ||
![]() | Gets or sets PartitionKeyDefinition object in the Azure DocumentDB database service. | |
![]() | Gets or sets the Resource Id associated with the resource in the Azure DocumentDB database service. (Inherited from Resource.) | |
![]() | Gets the self-link associated with the resource from the Azure DocumentDB database service. (Inherited from Resource.) | |
![]() | Gets the self-link for stored procedures in a collection from the Azure DocumentDB database service. | |
![]() | Gets the last modified timestamp associated with the resource from the Azure DocumentDB database service. (Inherited from Resource.) | |
![]() | Gets the self-link for triggers in a collection from the Azure DocumentDB database service. | |
![]() | Gets the self-link for user defined functions in a collection from the Azure DocumentDB database service. |
| Name | Description | |
|---|---|---|
![]() | Equals | (Inherited from Object.) |
![]() | Finalize | (Inherited from Object.) |
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetPropertyValue | Gets property value associated with the specified property name from the Azure DocumentDB database service. (Inherited from Resource.) |
![]() | GetType | (Inherited from Object.) |
![]() | LoadFrom | Loads the object from the specified JSON reader in the Azure DocumentDB database service. (Inherited from JsonSerializable.) |
![]() | MemberwiseClone | (Inherited from Object.) |
![]() | SaveTo | Saves the object to the specified stream in the Azure DocumentDB database service. (Inherited from JsonSerializable.) |
![]() | SetPropertyValue | Sets property value associated with the specified property name in the Azure DocumentDB database service. (Inherited from Resource.) |
![]() | ToByteArray | Serialize to a byte array via SaveTo for the Azure DocumentDB database service. (Inherited from Resource.) |
![]() | ToString | Returns the string representation of the object in the Azure DocumentDB database service. (Inherited from JsonSerializable.) |
| Name | Description | |
|---|---|---|
![]() | IsDefined | Determines if a certain property is defined or not. (Defined by TypeCheckFunctionsExtensions.) |
![]() | IsNull | Determines if a certain property is null or not. (Defined by TypeCheckFunctionsExtensions.) |
![]() | IsPrimitive | Determines if a certain property is of premitive JSON type. (Defined by TypeCheckFunctionsExtensions.) |
A database may contain zero or more named collections and each collection consists of zero or more JSON documents. Being schema-free, the documents in a collection do not need to share the same structure or fields. Since collections are application resources, they can be authorized using either the master key or resource keys. Refer to for more details on collections.
The example below creates a new partitioned collection with 50000 Request-per-Unit throughput. The partition key is the first level 'country' property in all the documents within this collection.
DocumentCollection collection = await client.CreateDocumentCollectionAsync( databaseLink, new DocumentCollection { Id = "MyCollection", PartitionKey = new PartitionKeyDefinition { Paths = new Collection<string> { "/country" } } }, new RequestOptions { OfferThroughput = 50000} ).Result;
The example below creates a new collection with a custom indexing policy.
DocumentCollection collectionSpec = new DocumentCollection { Id ="MyCollection" }; collectionSpec.IndexingPolicy.Automatic = true; collectionSpec.IndexingPolicy.IndexingMode = IndexingMode.Consistent; collection = await client.CreateDocumentCollectionAsync(database.SelfLink, collectionSpec);
The example below deletes this collection.
await client.DeleteDocumentCollectionAsync(collection.SelfLink);
The example below creates a new collection with OfferThroughput set to 10000.
DocumentCollection collection = await client.CreateDocumentCollectionAsync( databaseLink, new DocumentCollection { Id = "MyCollection" }, new RequestOptions { OfferThroughput = 10000} ).Result;
The example below queries for a Database by Id to retrieve the SelfLink.
using Microsoft.Azure.Documents.Linq; DocumentCollection collection = client.CreateDocumentCollectionQuery(databaseLink).Where(c => c.Id == "myColl").AsEnumerable().FirstOrDefault(); string collectionLink = collection.SelfLink;
The example below creates a document of type Book inside this collection.
Document doc = await client.CreateDocumentAsync(collection.SelfLink, new Book { Title = "War and Peace" });
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


