Table of Contents

Class Database

Namespace
Microsoft.Azure.Documents
Assembly
Microsoft.Azure.Documents.Client.dll

Represents a database in the Azure Cosmos DB account.

public class Database : Resource
Inheritance
Database
Inherited Members
Extension Methods

Examples

The example below creates a new Database with an Id property of 'MyDatabase'.

using (DocumentClient client = new DocumentClient(new Uri("service endpoint"), "auth key"))
{
    Database db = await client.CreateDatabaseAsync(new Database { Id = "MyDatabase" });
}

The example below creates a collection within this database with OfferThroughput set to 10000.

DocumentCollection coll = await client.CreateDocumentCollectionAsync(db.SelfLink,
    new DocumentCollection { Id = "MyCollection" }, 
    new RequestOptions { OfferThroughput = 10000} );

The example below queries for a Database by Id to retrieve the SelfLink.

using Microsoft.Azure.Documents.Linq;
Database database = client.CreateDatabaseQuery().Where(d => d.Id == "MyDatabase").AsEnumerable().FirstOrDefault();
string databaseLink = database.SelfLink;

The example below deletes the database using its SelfLink property.

await client.DeleteDatabaseAsync(db.SelfLink);

Remarks

Each Azure Cosmos DB database account can have zero or more databases. A database in Azure Cosmos DB is a logical container for document collections and users. Refer to http://azure.microsoft.com/documentation/articles/documentdb-resources/#databases for more details on databases.

Constructors

Database()

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

public Database()

Properties

Gets the self-link for collections from the Azure Cosmos DB service.

public string CollectionsLink { get; }

Property Value

string

The self-link for collections in the database.

Every Azure Cosmos DB resource has a static, immutable, addressable URI. For collections, this takes the form of; /dbs/db_rid/colls/ where db_rid represents the value of the database's resource id. A resource id is not the id given to a database on creation, but an internally generated immutable id.

Gets the self-link for users from the Azure Cosmos DB service.

public string UsersLink { get; }

Property Value

string

The self-link for users in the database.

Every Azure Cosmos DB resource has a static, immutable, addressable URI. For users, this takes the form of; /dbs/db_rid/users/ where db_rid represents the value of the database's resource id. A resource id is not the id given to a database on creation, but an internally generated immutable id.

See Also