選項
首頁首頁 Skill 開發營運和 CI/CD azure-mgmt-mongodbatlas-dotnet

azure-mgmt-mongodbatlas-dotnet

microsoft/skills microsoft/skills

透過 Azure Marketplace,將 MongoDB Atlas 組織作為 Azure ARM 資源進行管理,並採用統一計費方式。使用 Azure.ResourceManager.MongoDBAtlas SDK 來建立、更新、列出或刪除 Atlas 組織。

...展開全部
0
更新時間 2026-09-15

Azure.ResourceManager.MongoDBAtlas SDK

透過 Azure Marketplace,將 MongoDB Atlas 組織作為 Azure ARM 資源進行管理,並採用統一計費機制。

套件資訊

屬性
套件 Azure.ResourceManager.MongoDBAtlas
版本 1.0.0 (GA)
API 版本 2025-06-01
資源類型 MongoDB.Atlas/organizations
NuGet Azure.ResourceManager.MongoDBAtlas

安裝

dotnet add package Azure.ResourceManager.MongoDBAtlas
dotnet add package Azure.Identity
dotnet add package Azure.ResourceManager

重要範圍限制

此 SDK 將MongoDB Atlas 組織作為 Azure ARM 資源進行管理,以實現與市集的整合。它並不會直接管理:

  • Atlas 叢集
  • 資料庫
  • 集合
  • 使用者/角色

若需管理叢集,請在建立組織後直接使用 MongoDB Atlas API。

環境變數

AZURE_SUBSCRIPTION_ID= # 必填:Azure 訂閱 ID
AZURE_RESOURCE_GROUP= # 必填:Azure 資源群組名稱
AZURE_TOKEN_CREDENTIALS=prod  # 僅當在生產環境中使用 DefaultAzureCredential 時才需填寫
AZURE_TENANT_ID= # 用於服務主體驗證(可選)
AZURE_CLIENT_ID= # 用於服務主體驗證(可選)
AZURE_CLIENT_SECRET= # 用於服務主體驗證(可選)

驗證

using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.MongoDBAtlas;
using Azure.ResourceManager.MongoDBAtlas.Models;

// 本地開發環境:DefaultAzureCredential。 生產環境:設定 AZURE_TOKEN_CREDENTIALS=prod 或 AZURE_TOKEN_CREDENTIALS=
var credential = new DefaultAzureCredential(
    DefaultAzureCredential.DefaultEnvironmentVariableName
);
// 或在生產環境中直接使用特定憑證:
// 請參閱 https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#credential-classes
// var credential = new ManagedIdentityCredential();
var armClient = new ArmClient(credential);

核心類型

類型 用途
MongoDBAtlasOrganizationResource 代表 Atlas 組織的 ARM 資源
MongoDBAtlasOrganizationCollection 資源群組中的組織集合
MongoDBAtlasOrganizationData 組織資源的資料模型
MongoDBAtlasOrganizationProperties 組織專屬屬性
MongoDBAtlasMarketplaceDetails Azure Marketplace 訂閱詳細資訊
MongoDBAtlasOfferDetails 市集方案設定
MongoDBAtlasUserDetails 組織的用戶資訊
MongoDBAtlasPartnerProperties MongoDB 專屬屬性(組織名稱、ID)

工作流程

取得組織集合

// 取得資源群組
var subscription = await armClient.GetDefaultSubscriptionAsync();
var resourceGroup = await subscription.GetResourceGroupAsync("my-resource-group");

// 取得組織集合
MongoDBAtlasOrganizationCollection organizations = 
    resourceGroup.Value.GetMongoDBAtlasOrganizations();

建立組織

var organizationName = "my-atlas-org";
var location = AzureLocation.EastUS2;

// 建立組織資料
var organizationData = new MongoDBAtlasOrganizationData(location)
{
    Properties = new MongoDBAtlasOrganizationProperties(
        marketplace: new MongoDBAtlasMarketplaceDetails(
            subscriptionId: "您的 Azure 訂閱 ID",
            offerDetails: new MongoDBAtlasOfferDetails(
                publisherId: "mongodb",
                offerId: "mongodb_atlas_azure_native_prod",
                planId: "private_plan",
                planName: "隨用隨付 (免費) (私有)",
                合約單位: "P1M",
                合約 ID: "gmz7xq9ge3py"
            )
        ),
        user: new MongoDBAtlasUserDetails(
            emailAddress: "[email protected]",
            upn: "[email protected]"
        )
        {
            FirstName = "Admin",
            LastName = "User"
        }
    )
    {
        PartnerProperties = new MongoDBAtlasPartnerProperties
        {
            OrganizationName = organizationName
        }
    },
    Tags = { ["Environment"] = "Production" }
};

// 建立組織(長時間執行的操作)
var operation = await organizations.CreateOrUpdateAsync(
    WaitUntil.Completed,
    organizationName,
    organizationData
);

MongoDBAtlasOrganizationResource organization = operation.Value;
Console.WriteLine($"已建立:{organization.Id}");

取得現有組織

// 選項 1:從集合取得
MongoDBAtlasOrganizationResource org = 
    await organizations.GetAsync("my-atlas-org");

// 選項 2:從資源識別碼取得
var resourceId = MongoDBAtlasOrganizationResource.CreateResourceIdentifier(
    subscriptionId: "subscription-id",
    resourceGroupName: "my-resource-group",
    organizationName: "my-atlas-org"
);
MongoDBAtlasOrganizationResource org2 = 
    armClient.GetMongoDBAtlasOrganizationResource(resourceId);
await org2.GetAsync(); // 擷取資料

列出組織

// 列出資源群組中的組織
await foreach (var org in organizations.GetAllAsync())
{
    Console.WriteLine($"組織:{org.Data.Name}");
    Console.WriteLine($"  位置:{org.Data.Location}");
    Console.WriteLine($"  狀態:{org.Data.Properties?.ProvisioningState}");
}

// 列出所有訂閱中的組織
await foreach (var org in subscription.GetMongoDBAtlasOrganizationsAsync())
{
    Console.WriteLine($"組織:{org.Data.Name},位於 {org.Data.Id}");
}

更新標籤

// 新增單一標籤
await organization.AddTagAsync("CostCenter", "12345");

// 替換所有標籤
await organization.SetTagsAsync(new Dictionary{
    ["Environment"] = "Production",
    ["Team"] = "Platform"
});

// 移除一個標籤
await organization.RemoveTagAsync("OldTag");

更新組織屬性

var patch = new MongoDBAtlasOrganizationPatch
{
    Tags = { ["UpdatedAt"] = DateTime.UtcNow.ToString("o") },
    Properties = new MongoDBAtlasOrganizationUpdateProperties
    {
        // 如有需要,更新使用者詳細資料
        User = new MongoDBAtlasUserDetails(
            emailAddress: "[email protected]",
            upn: "[email protected]"
        )
    }
};

var updateOperation = await organization.UpdateAsync(
    WaitUntil.Completed,
    patch
);

刪除組織

// 刪除(長期執行操作)
await organization.DeleteAsync(WaitUntil.Completed);

模型屬性參考

MongoDBAtlasOrganizationProperties

屬性 類型 說明
市場 MongoDBAtlasMarketplaceDetails 必填。市集訂閱詳細資訊
使用者 MongoDBAtlasUserDetails 必填。組織管理員使用者
合作夥伴屬性 MongoDBAtlasPartnerProperties MongoDB 專屬屬性
配置狀態 MongoDBAtlasResourceProvisioningState 唯讀。當前配置狀態

MongoDBAtlasMarketplaceDetails

屬性 類型 說明
SubscriptionId 字串 必填。用於計費的 Azure 訂閱 ID
優惠詳情 MongoDBAtlasOfferDetails 必填。Marketplace 方案設定
訂閱狀態 MarketplaceSubscriptionStatus 唯讀。訂閱狀態

MongoDBAtlasOfferDetails

屬性 類型 說明
PublisherId 字串 必填。發佈者 ID(通常為「mongodb」)
OfferId 字串 必填。優惠編號
PlanId 字串 必填。方案 ID
方案名稱 字串 必填。計畫的顯示名稱
TermUnit 字串 必填。計費週期單位(例如:「P1M」)
TermId 字串 必填。計費週期識別碼

MongoDBAtlasUserDetails

屬性 類型 說明
電子郵件地址 字串 必填。使用者的電子郵件地址
UPN 字串 必填。使用者主體名稱
FirstName 字串 可選。使用者名字
LastName 字串 可選。使用者的姓氏

MongoDBAtlasPartnerProperties

屬性 類型 說明
組織名稱 字串 MongoDB Atlas 組織的名稱
組織 ID 字串 唯讀。MongoDB Atlas 組織 ID

配置狀態

狀態 描述
成功 資源已成功配置
失敗 配置失敗
已取消 資源配置已被取消
正在配置 正在進行資源配置
正在更新 正在更新資源
刪除中 正在刪除資源
已接受 請求已接受,正在進行配置

市集訂閱狀態

狀態 說明
待履行開始 訂閱待啟用
已訂閱 訂閱已啟用
已暫停 訂閱已暫停
已取消訂閱 訂閱已取消

最佳實務

使用非同步方法

// 建議所有操作皆使用非同步方式
var org = await organizations.GetAsync("my-org");
await org.Value.AddTagAsync("key", "value");

處理長時間執行的操作

// 等待完成
var operation = await organizations.CreateOrUpdateAsync(
    WaitUntil.Completed,  // 阻塞直至完成
    name,
    data
);

// 或先啟動,稍後輪詢
var operation = await organizations.CreateOrUpdateAsync(
    WaitUntil.Completed,  // 立即返回
    name,
    data
);

// 輪詢完成狀態
while (!operation.HasCompleted)
{
    await Task.Delay(TimeSpan.FromSeconds(5));
    await operation.UpdateStatusAsync();
}

檢查配置狀態

var org = await organizations.GetAsync("my-org");
if (org.Value.Data.Properties?.ProvisioningState == 
    MongoDBAtlasResourceProvisioningState.Succeeded)
{
    Console.WriteLine("組織已就緒");
}

使用資源識別碼

// 無需呼叫 API 即可建立識別碼
var resourceId = MongoDBAtlasOrganizationResource.CreateResourceIdentifier(
    subscriptionId,
    resourceGroupName,
    organizationName
);

// 取得資源處理程序 (目前尚無資料)
var orgResource = armClient.GetMongoDBAtlasOrganizationResource(resourceId);

// 需要時擷取資料
var response = await orgResource.GetAsync();

常見錯誤

錯誤 原因 解決方案
ResourceNotFound 組織不存在 請確認名稱和資源群組
授權失敗 權限不足 請檢查資源群組上的 RBAC 角色
參數無效 缺少必填屬性 請確保所有必填欄位均已設定
MarketplaceError Marketplace 訂閱問題 請驗證優惠詳情及訂閱資訊

相關資源

  • Microsoft Learn:Azure 上的 MongoDB Atlas
  • API 參考
  • Azure .NET SDK
在 GitHub 上查看
---
name: azure-mgmt-mongodbatlas-dotnet
description: Manage MongoDB Atlas Organizations as Azure ARM resources with unified billing through Azure Marketplace. Create, update, list, or delete Atlas organizations using the Azure.ResourceManager.MongoDBAtlas SDK.
license: MIT
---

# Azure.ResourceManager.MongoDBAtlas SDK

Manage MongoDB Atlas Organizations as Azure ARM resources with unified billing through Azure Marketplace.

## Package Information

| Property | Value |
|----------|-------|
| Package | `Azure.ResourceManager.MongoDBAtlas` |
| Version | 1.0.0 (GA) |
| API Version | 2025-06-01 |
| Resource Type | `MongoDB.Atlas/organizations` |
| NuGet | [Azure.ResourceManager.MongoDBAtlas](https://www.nuget.org/packages/Azure.ResourceManager.MongoDBAtlas) |

## Installation

```bash
dotnet add package Azure.ResourceManager.MongoDBAtlas
dotnet add package Azure.Identity
dotnet add package Azure.ResourceManager
```

## Important Scope Limitation

This SDK manages **MongoDB Atlas Organizations as Azure ARM resources** for marketplace integration. It does NOT directly manage:
- Atlas clusters
- Databases
- Collections
- Users/roles

For cluster management, use the MongoDB Atlas API directly after creating the organization.

## Environment Variables

```bash
AZURE_SUBSCRIPTION_ID=<your-subscription-id> # Required: Azure subscription ID
AZURE_RESOURCE_GROUP=<your-resource-group> # Required: Azure resource group name
AZURE_TOKEN_CREDENTIALS=prod  # Required only if DefaultAzureCredential is used in production
AZURE_TENANT_ID=<your-tenant-id> # For service principal auth (optional)
AZURE_CLIENT_ID=<your-client-id> # For service principal auth (optional)
AZURE_CLIENT_SECRET=<your-client-secret> # For service principal auth (optional)
```

## Authentication

```csharp
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.MongoDBAtlas;
using Azure.ResourceManager.MongoDBAtlas.Models;

// Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
var credential = new DefaultAzureCredential(
    DefaultAzureCredential.DefaultEnvironmentVariableName
);
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#credential-classes
// var credential = new ManagedIdentityCredential();
var armClient = new ArmClient(credential);
```

## Core Types

| Type | Purpose |
|------|---------|
| `MongoDBAtlasOrganizationResource` | ARM resource representing an Atlas organization |
| `MongoDBAtlasOrganizationCollection` | Collection of organizations in a resource group |
| `MongoDBAtlasOrganizationData` | Data model for organization resource |
| `MongoDBAtlasOrganizationProperties` | Organization-specific properties |
| `MongoDBAtlasMarketplaceDetails` | Azure Marketplace subscription details |
| `MongoDBAtlasOfferDetails` | Marketplace offer configuration |
| `MongoDBAtlasUserDetails` | User information for the organization |
| `MongoDBAtlasPartnerProperties` | MongoDB-specific properties (org name, ID) |

## Workflows

### Get Organization Collection

```csharp
// Get resource group
var subscription = await armClient.GetDefaultSubscriptionAsync();
var resourceGroup = await subscription.GetResourceGroupAsync("my-resource-group");

// Get organizations collection
MongoDBAtlasOrganizationCollection organizations = 
    resourceGroup.Value.GetMongoDBAtlasOrganizations();
```

### Create Organization

```csharp
var organizationName = "my-atlas-org";
var location = AzureLocation.EastUS2;

// Build organization data
var organizationData = new MongoDBAtlasOrganizationData(location)
{
    Properties = new MongoDBAtlasOrganizationProperties(
        marketplace: new MongoDBAtlasMarketplaceDetails(
            subscriptionId: "your-azure-subscription-id",
            offerDetails: new MongoDBAtlasOfferDetails(
                publisherId: "mongodb",
                offerId: "mongodb_atlas_azure_native_prod",
                planId: "private_plan",
                planName: "Pay as You Go (Free) (Private)",
                termUnit: "P1M",
                termId: "gmz7xq9ge3py"
            )
        ),
        user: new MongoDBAtlasUserDetails(
            emailAddress: "[email protected]",
            upn: "[email protected]"
        )
        {
            FirstName = "Admin",
            LastName = "User"
        }
    )
    {
        PartnerProperties = new MongoDBAtlasPartnerProperties
        {
            OrganizationName = organizationName
        }
    },
    Tags = { ["Environment"] = "Production" }
};

// Create the organization (long-running operation)
var operation = await organizations.CreateOrUpdateAsync(
    WaitUntil.Completed,
    organizationName,
    organizationData
);

MongoDBAtlasOrganizationResource organization = operation.Value;
Console.WriteLine($"Created: {organization.Id}");
```

### Get Existing Organization

```csharp
// Option 1: From collection
MongoDBAtlasOrganizationResource org = 
    await organizations.GetAsync("my-atlas-org");

// Option 2: From resource identifier
var resourceId = MongoDBAtlasOrganizationResource.CreateResourceIdentifier(
    subscriptionId: "subscription-id",
    resourceGroupName: "my-resource-group",
    organizationName: "my-atlas-org"
);
MongoDBAtlasOrganizationResource org2 = 
    armClient.GetMongoDBAtlasOrganizationResource(resourceId);
await org2.GetAsync(); // Fetch data
```

### List Organizations

```csharp
// List in resource group
await foreach (var org in organizations.GetAllAsync())
{
    Console.WriteLine($"Org: {org.Data.Name}");
    Console.WriteLine($"  Location: {org.Data.Location}");
    Console.WriteLine($"  State: {org.Data.Properties?.ProvisioningState}");
}

// List across subscription
await foreach (var org in subscription.GetMongoDBAtlasOrganizationsAsync())
{
    Console.WriteLine($"Org: {org.Data.Name} in {org.Data.Id}");
}
```

### Update Tags

```csharp
// Add a single tag
await organization.AddTagAsync("CostCenter", "12345");

// Replace all tags
await organization.SetTagsAsync(new Dictionary<string, string>
{
    ["Environment"] = "Production",
    ["Team"] = "Platform"
});

// Remove a tag
await organization.RemoveTagAsync("OldTag");
```

### Update Organization Properties

```csharp
var patch = new MongoDBAtlasOrganizationPatch
{
    Tags = { ["UpdatedAt"] = DateTime.UtcNow.ToString("o") },
    Properties = new MongoDBAtlasOrganizationUpdateProperties
    {
        // Update user details if needed
        User = new MongoDBAtlasUserDetails(
            emailAddress: "[email protected]",
            upn: "[email protected]"
        )
    }
};

var updateOperation = await organization.UpdateAsync(
    WaitUntil.Completed,
    patch
);
```

### Delete Organization

```csharp
// Delete (long-running operation)
await organization.DeleteAsync(WaitUntil.Completed);
```

## Model Properties Reference

### MongoDBAtlasOrganizationProperties

| Property | Type | Description |
|----------|------|-------------|
| `Marketplace` | `MongoDBAtlasMarketplaceDetails` | Required. Marketplace subscription details |
| `User` | `MongoDBAtlasUserDetails` | Required. Organization admin user |
| `PartnerProperties` | `MongoDBAtlasPartnerProperties` | MongoDB-specific properties |
| `ProvisioningState` | `MongoDBAtlasResourceProvisioningState` | Read-only. Current provisioning state |

### MongoDBAtlasMarketplaceDetails

| Property | Type | Description |
|----------|------|-------------|
| `SubscriptionId` | `string` | Required. Azure subscription ID for billing |
| `OfferDetails` | `MongoDBAtlasOfferDetails` | Required. Marketplace offer configuration |
| `SubscriptionStatus` | `MarketplaceSubscriptionStatus` | Read-only. Subscription status |

### MongoDBAtlasOfferDetails

| Property | Type | Description |
|----------|------|-------------|
| `PublisherId` | `string` | Required. Publisher ID (typically "mongodb") |
| `OfferId` | `string` | Required. Offer ID |
| `PlanId` | `string` | Required. Plan ID |
| `PlanName` | `string` | Required. Display name of the plan |
| `TermUnit` | `string` | Required. Billing term unit (e.g., "P1M") |
| `TermId` | `string` | Required. Term identifier |

### MongoDBAtlasUserDetails

| Property | Type | Description |
|----------|------|-------------|
| `EmailAddress` | `string` | Required. User email address |
| `Upn` | `string` | Required. User principal name |
| `FirstName` | `string` | Optional. User first name |
| `LastName` | `string` | Optional. User last name |

### MongoDBAtlasPartnerProperties

| Property | Type | Description |
|----------|------|-------------|
| `OrganizationName` | `string` | Name of the MongoDB Atlas organization |
| `OrganizationId` | `string` | Read-only. MongoDB Atlas organization ID |

## Provisioning States

| State | Description |
|-------|-------------|
| `Succeeded` | Resource provisioned successfully |
| `Failed` | Provisioning failed |
| `Canceled` | Provisioning was canceled |
| `Provisioning` | Resource is being provisioned |
| `Updating` | Resource is being updated |
| `Deleting` | Resource is being deleted |
| `Accepted` | Request accepted, provisioning starting |

## Marketplace Subscription Status

| Status | Description |
|--------|-------------|
| `PendingFulfillmentStart` | Subscription pending activation |
| `Subscribed` | Active subscription |
| `Suspended` | Subscription suspended |
| `Unsubscribed` | Subscription canceled |

## Best Practices

### Use Async Methods

```csharp
// Prefer async for all operations
var org = await organizations.GetAsync("my-org");
await org.Value.AddTagAsync("key", "value");
```

### Handle Long-Running Operations

```csharp
// Wait for completion
var operation = await organizations.CreateOrUpdateAsync(
    WaitUntil.Completed,  // Blocks until done
    name,
    data
);

// Or start and poll later
var operation = await organizations.CreateOrUpdateAsync(
    WaitUntil.Started,  // Returns immediately
    name,
    data
);

// Poll for completion
while (!operation.HasCompleted)
{
    await Task.Delay(TimeSpan.FromSeconds(5));
    await operation.UpdateStatusAsync();
}
```

### Check Provisioning State

```csharp
var org = await organizations.GetAsync("my-org");
if (org.Value.Data.Properties?.ProvisioningState == 
    MongoDBAtlasResourceProvisioningState.Succeeded)
{
    Console.WriteLine("Organization is ready");
}
```

### Use Resource Identifiers

```csharp
// Create identifier without API call
var resourceId = MongoDBAtlasOrganizationResource.CreateResourceIdentifier(
    subscriptionId,
    resourceGroupName,
    organizationName
);

// Get resource handle (no data yet)
var orgResource = armClient.GetMongoDBAtlasOrganizationResource(resourceId);

// Fetch data when needed
var response = await orgResource.GetAsync();
```

## Common Errors

| Error | Cause | Solution |
|-------|-------|----------|
| `ResourceNotFound` | Organization doesn't exist | Verify name and resource group |
| `AuthorizationFailed` | Insufficient permissions | Check RBAC roles on resource group |
| `InvalidParameter` | Missing required properties | Ensure all required fields are set |
| `MarketplaceError` | Marketplace subscription issue | Verify offer details and subscription |

## Related Resources

- [Microsoft Learn: MongoDB Atlas on Azure](https://learn.microsoft.com/en-us/azure/partner-solutions/mongodb-atlas/)
- [API Reference](https://learn.microsoft.com/en-us/dotnet/api/azure.resourcemanager.mongodbatlas)
- [Azure SDK for .NET](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/mongodbatlas)

所有檔案

1 個檔案

安裝 azure-mgmt-mongodbatlas-dotnet

請下載並將技能檔案解壓縮至您的 .claude/skills/ 目錄中。

下載 ZIP

複製儲存庫並將技能檔案複製到您的專案中。

git clone https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-mongodbatlas-dotnet # Copy SKILL.md to your .claude/skills/ directory

複製 複製
快速設定: 將技能資料夾複製到 .claude/skills/ Claude 會自動偵測並使用該技能
儲存庫 microsoft/skills

相關技能

base44-cli
更新時間 2026-06-29
klingai-upgrade-migration
更新時間 2026-07-03
Railway CLI Management
更新時間 2026-07-02
Verification &amp; Quality Assurance
更新時間 2026-06-29
OR