共用方式為


DocumentCollection Class

Definition

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

public class DocumentCollection : Microsoft.Azure.Documents.Resource
type DocumentCollection = class
    inherit Resource
Public Class DocumentCollection
Inherits Resource
Inheritance
DocumentCollection

Examples

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 OfferThroughput set to 10000.

DocumentCollection collection = await client.CreateDocumentCollectionAsync(
    databaseLink,
    new DocumentCollection { Id = "MyCollection" }, 
    new RequestOptions { OfferThroughput = 10000} ).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 creates a document of type Book inside this collection.

Document doc = await client.CreateDocumentAsync(collection.SelfLink, new Book { Title = "War and Peace" });

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 deletes this collection.

await client.DeleteDocumentCollectionAsync(collection.SelfLink);

Remarks

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.

Constructors

DocumentCollection()

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

Properties

AltLink

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

(Inherited from Resource)
ConflictResolutionPolicy

Gets or sets the ConflictResolutionPolicy that is used for resolving conflicting writes on documents in different regions, in a collection in the Azure Cosmos DB service.

ConflictsLink

Gets the self-link for conflicts in a collection from the Azure Cosmos DB service.

DefaultTimeToLive

Gets the default time to live in seconds for documents in a collection from the Azure Cosmos DB service.

DocumentsLink

Gets the self-link for documents in a collection from the Azure Cosmos DB service.

ETag

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

(Inherited from Resource)
GeospatialConfig

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

Id

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

(Inherited from Resource)
IndexingPolicy

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

PartitionKey

Gets or sets PartitionKeyDefinition object in the Azure Cosmos DB service.

PartitionKeyDeleteThroughputFraction
Obsolete.

Gets or sets the PartitionKeyDeleteThroughputFraction for the collection.

PartitionKeyRangeStatistics

Gets a collection of PartitionKeyRangeStatistics object in the Azure Cosmos DB service.

ResourceId

Gets or sets the Resource Id associated with the resource in the Azure Cosmos DB service.

(Inherited from Resource)
SelfLink

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

(Inherited from Resource)
StoredProceduresLink

Gets the self-link for stored procedures in a collection from the Azure Cosmos DB service.

Timestamp

Gets the last modified timestamp associated with the resource from the Azure Cosmos DB service.

(Inherited from Resource)
TimeToLivePropertyPath

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

TriggersLink

Gets the self-link for triggers in a collection from the Azure Cosmos DB service.

UniqueKeyPolicy

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

UserDefinedFunctionsLink

Gets the self-link for user defined functions in a collection from the Azure Cosmos DB service.

Methods

GetPropertyValue<T>(String)

Gets property value associated with the specified property name from the Azure Cosmos DB service.

(Inherited from Resource)
LoadFrom(JsonReader, JsonSerializerSettings)

Loads the object from the specified JSON reader in the Azure Cosmos DB service.

(Inherited from JsonSerializable)
LoadFrom(JsonReader)

Loads the object from the specified JSON reader in the Azure Cosmos DB service.

(Inherited from JsonSerializable)
SaveTo(Stream, SerializationFormattingPolicy, JsonSerializerSettings)

Saves the object to the specified stream in the Azure Cosmos DB service.

(Inherited from JsonSerializable)
SaveTo(Stream, SerializationFormattingPolicy)

Saves the object to the specified stream in the Azure Cosmos DB service.

(Inherited from JsonSerializable)
SetPropertyValue(String, Object)

Sets property value associated with the specified property name in the Azure Cosmos DB service.

(Inherited from Resource)
ToByteArray()

Serialize to a byte array via SaveTo for the Azure Cosmos DB service.

(Inherited from Resource)
ToString()

Returns the string representation of the object in the Azure Cosmos DB service.

(Inherited from JsonSerializable)

Applies to

See also