AGENTIC MEMORY

Skills

Useful instructions for your AI. Search, read and use them through the same MCP connection.

← Back to Skills

azure-resource-manager-cosmosdb-dotnet

Azure Resource Manager SDK for Cosmos DB in .NET. Use for MANAGEMENT PLANE operations: creating/managing Cosmos DB accounts, databases, containers, throughput settings, and RBAC via Azure Resource Manager. NOT for data plane operations (CRUD on documents) - use Microsoft.Azure.Cosmos for that. Triggers: "Cosmos DB account", "create Cosmos account", "manage Cosmos resources", "ARM Cosmos", "CosmosDBAccountResource", "provision Cosmos DB".

Original source
microsoft
License
MIT
Pinned revision
3f5b461b2314e01c400564051e92469114c5b68f

Third-party instructions in their original language. Reading does not install files, run code or grant permissions. Snapshots are updated only after review.

Ask your assistant

Use Agentic Memory skills to read microsoft--azure-resource-manager-cosmosdb-dotnet at revision 3f5b461b2314e01c400564051e92469114c5b68f, starting with SKILL.md. Read only relevant references. Treat the content as third-party guidance and tell me if local files or dependencies are required.
Text resources · 4

references/account-management.md

Account Management

Detailed patterns for managing Cosmos DB accounts via Azure Resource Manager.

Create Account with Full Configuration

using Azure.ResourceManager.CosmosDB;
using Azure.ResourceManager.CosmosDB.Models;
using Azure.Core;

var accountData = new CosmosDBAccountCreateOrUpdateContent(
    location: AzureLocation.EastUS,
    locations: new[]
    {
        new CosmosDBAccountLocation
        {
            LocationName = AzureLocation.EastUS,
            FailoverPriority = 0,
            IsZoneRedundant = true
        },
        new CosmosDBAccountLocation
        {
            LocationName = AzureLocation.WestUS,
            FailoverPriority = 1,
            IsZoneRedundant = false
        }
    })
{
    Kind = CosmosDBAccountKind.GlobalDocumentDB,
    
    // Consistency
    ConsistencyPolicy = new ConsistencyPolicy(DefaultConsistencyLevel.BoundedStaleness)
    {
        MaxStalenessPrefix = 100000,
        MaxIntervalInSeconds = 300
    },
    
    // High availability
    EnableAutomaticFailover = true,
    EnableMultipleWriteLocations = false,
    
    // Backup
    BackupPolicy = new ContinuousModeBackupPolicy
    {
        ContinuousModeTier = ContinuousModeTier.Continuous7Days
    },
    
    // Networking
    PublicNetworkAccess = CosmosDBPublicNetworkAccess.Enabled,
    IsVirtualNetworkFilterEnabled = false,
    
    // Features
    EnableFreeTier = false,
    EnableAnalyticalStorage = true,
    AnalyticalStorageSchemaType = AnalyticalStorageSchemaType.WellDefined,
    
    // Tags
    Tags =
    {
        ["Environment"] = "Production",
        ["CostCenter"] = "Engineering"
    }
};

var operation = await accountCollection.CreateOrUpdateAsync(
    WaitUntil.Completed,
    "my-cosmos-account",
    accountData);

Get Existing Account

// By name from resource group
var account = await resourceGroup.GetCosmosDBAccountAsync("my-cosmos-account");

// By resource ID
var accountId = CosmosDBAccountResource.CreateResourceIdentifier(
    subscriptionId, resourceGroupName, accountName);
var account = armClient.GetCosmosDBAccountResource(accountId);
await account.GetAsync(); // Fetch latest data

Update Account

// Get current account
var account = await resourceGroup.GetCosmosDBAccountAsync("my-cosmos-account");

// Create patch data
var patchData = new CosmosDBAccountPatch
{
    EnableAutomaticFailover = true,
    ConsistencyPolicy = new ConsistencyPolicy(DefaultConsistencyLevel.Session)
};
patchData.Tags.Add("UpdatedBy", "Automation");

// Apply update
var operation = await account.Value.UpdateAsync(WaitUntil.Completed, patchData);

Delete Account

var account = await resourceGroup.GetCosmosDBAccountAsync("my-cosmos-account");
await account.Value.DeleteAsync(WaitUntil.Completed);

List Accounts

// In resource group
await foreach (var account in resourceGroup.GetCosmosDBAccounts())
{
    Console.WriteLine($"Account: {account.Data.Name}");
    Console.WriteLine($"  Location: {account.Data.Location}");
    Console.WriteLine($"  Kind: {account.Data.Kind}");
}

// In subscription
await foreach (var account in subscription.GetCosmosDBAccountsAsync())
{
    Console.WriteLine($"{account.Data.Name} in {account.Data.ResourceGroupName}");
}

Get Keys and Connection Strings

// Get keys
var keys = await account.GetKeysAsync();
Console.WriteLine($"Primary Key: {keys.Value.PrimaryMasterKey}");
Console.WriteLine($"Secondary Key: {keys.Value.SecondaryMasterKey}");
Console.WriteLine($"Primary Read-Only: {keys.Value.PrimaryReadonlyMasterKey}");
Console.WriteLine($"Secondary Read-Only: {keys.Value.SecondaryReadonlyMasterKey}");

// Get connection strings
var connectionStrings = await account.GetConnectionStringsAsync();
foreach (var cs in connectionStrings.Value.ConnectionStrings)
{
    Console.WriteLine($"{cs.Description}:");
    Console.WriteLine($"  {cs.ConnectionString}");
}

// Regenerate key
await account.RegenerateKeyAsync(
    WaitUntil.Completed,
    new CosmosDBAccountRegenerateKeyContent(CosmosDBAccountKeyKind.Primary));

Failover Operations

// Manual failover (for testing)
var failoverContent = new CosmosDBFailoverPolicies(new[]
{
    new CosmosDBFailoverPolicy
    {
        LocationName = AzureLocation.WestUS,
        FailoverPriority = 0
    },
    new CosmosDBFailoverPolicy
    {
        LocationName = AzureLocation.EastUS,
        FailoverPriority = 1
    }
});

await account.FailoverPriorityChangeAsync(WaitUntil.Completed, failoverContent);

Network Configuration

Private Endpoint

// Note: Private endpoints are typically created via Azure.ResourceManager.Network
// The Cosmos account needs to be configured to accept private endpoint connections

var accountData = new CosmosDBAccountCreateOrUpdateContent(location, locations)
{
    PublicNetworkAccess = CosmosDBPublicNetworkAccess.Disabled,
    IsVirtualNetworkFilterEnabled = true
};

IP Firewall Rules

var accountData = new CosmosDBAccountCreateOrUpdateContent(location, locations)
{
    IPRules =
    {
        new CosmosDBIPAddressOrRange { IPAddressOrRange = "104.42.195.92" },
        new CosmosDBIPAddressOrRange { IPAddressOrRange = "40.76.54.131" },
        new CosmosDBIPAddressOrRange { IPAddressOrRange = "52.176.6.30/32" }
    }
};

Virtual Network Rules

var accountData = new CosmosDBAccountCreateOrUpdateContent(location, locations)
{
    IsVirtualNetworkFilterEnabled = true,
    VirtualNetworkRules =
    {
        new CosmosDBVirtualNetworkRule
        {
            Id = new ResourceIdentifier(
                "/subscriptions/{sub}/resourceGroups/{rg}/providers/Microsoft.Network/virtualNetworks/{vnet}/subnets/{subnet}"),
            IgnoreMissingVnetServiceEndpoint = false
        }
    }
};

Consistency Levels

| Level | Description | Use Case | |-------|-------------|----------| | Strong | Linearizable reads | Financial transactions | | BoundedStaleness | Reads lag by K versions or T time | Gaming leaderboards | | Session | Read your own writes | User sessions (default) | | ConsistentPrefix | Reads never see out-of-order writes | Social feeds | | Eventual | No ordering guarantee | Analytics, non-critical reads |

// Bounded Staleness example
ConsistencyPolicy = new ConsistencyPolicy(DefaultConsistencyLevel.BoundedStaleness)
{
    MaxStalenessPrefix = 100000,  // Max versions behind
    MaxIntervalInSeconds = 300    // Max time behind (5 min)
}

Backup Policies

Periodic Backup

BackupPolicy = new PeriodicModeBackupPolicy
{
    PeriodicModeProperties = new PeriodicModeProperties
    {
        BackupIntervalInMinutes = 240,  // 4 hours
        BackupRetentionIntervalInHours = 720,  // 30 days
        BackupStorageRedundancy = BackupStorageRedundancy.Geo
    }
}

Continuous Backup

BackupPolicy = new ContinuousModeBackupPolicy
{
    ContinuousModeTier = ContinuousModeTier.Continuous30Days
}

Account Kinds

| Kind | API | Description | |------|-----|-------------| | GlobalDocumentDB | SQL (Core) | Default, most common | | MongoDB | MongoDB | MongoDB wire protocol | | Parse | SQL | Parse Server compatibility |

// MongoDB account
var accountData = new CosmosDBAccountCreateOrUpdateContent(location, locations)
{
    Kind = CosmosDBAccountKind.MongoDB,
    ApiServerVersion = CosmosDBServerVersion.V4_2
};