
关于
将 MongoDB Atlas 组织作为 Azure ARM 资源管理,通过 Azure Marketplace 统一计费。
name: azure-mgmt-mongodbatlas-dotnet description: "将MongoDB Atlas组织作为Azure ARM资源进行管理,通过Azure Marketplace实现统一计费。" risk: unknown source: community date_added: "2026-02-27"
Azure.ResourceManager.MongoDBAtlas SDK
将MongoDB Atlas组织作为Azure ARM资源进行管理,通过Azure Marketplace实现统一计费。
包信息
| 属性 | 值 |
|----------|----------|
| 包 | 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资源进行管理,用于Marketplace集成。它不直接管理:
- Atlas集群
- 数据库
- 集合
- 用户/角色
要管理集群,请在创建组织后直接使用MongoDB Atlas API。
认证
using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.MongoDBAtlas;
using Azure.ResourceManager.MongoDBAtlas.Models;
// 使用DefaultAzureCredential创建ARM客户端
var credential = new DefaultAzureCredential();
var armClient = new ArmClient(credential);
核心类型
| 类型 | 用途 |
|------|---------|
| MongoDBAtlasOrganizationResource | 表示Atlas组织的ARM资源 |
| MongoDBAtlasOrganizationCollection | 资源组中的组织集合 |
| MongoDBAtlasOrganizationData | 组织资源的数据模型 |
| MongoDBAtlasOrganizationProperties | 组织特定属性 |
| MongoDBAtlasMarketplaceDetails | Azure Marketplace订阅详情 |
| MongoDBAtlasOfferDetails | Marketplace产品配置 |
| 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: "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: "admin@example.com",
upn: "admin@example.com"
)
{
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($"Created: {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: {org.Data.Name}");
Console.WriteLine($" Location: {org.Data.Location}");
Console.WriteLine($" State: {org.Data.Properties?.ProvisioningState}");
}
// 列出订阅中的所有组织
await foreach (var org in subscription.GetMongoDBAtlasOrganizationsAsync())
{
Console.WriteLine($"Org: {org.Data.Name}");
}