All Products
Search
Document Center

ApsaraDB for MongoDB:CLI integration example

Last Updated:Jun 22, 2026

Create an ApsaraDB for MongoDB replica set instance by using the Alibaba Cloud CLI.

For an introduction to the Alibaba Cloud CLI, see What is Alibaba Cloud CLI?.

Resource architecture

image.png

This template creates a Virtual Private Cloud (VPC) and a vSwitch in a specified region, and then creates an MongoDB replica set instance.

Install CLI

  • To install and configure the Alibaba Cloud CLI on your computer, see the Installation Guide.

  • Alternatively, use Cloud Shell, which provides a pre-installed CLI environment without local installation.

Configure permissions

The Alibaba Cloud CLI uses the credentials of the current user. Ensure that this user has the following permissions:

  • AliyunVPCFullAccess: permission to manage Virtual Private Cloud.

  • AliyunMongoDBFullAccess: permission to manage ApsaraDB for MongoDB.

Generate a CLI example

  1. Log on to OpenAPI Explorer.

  2. At the top of the page, click Select Cloud Products and select your target product.

  3. In the left-side navigation pane, click Test.

  4. On the API debugging page, use the left-side search box to find the desired API operation. On the Parameter Configuration tab, configure the parameters according to the API documentation. Click the CLI Example tab to the right of Parameter Configuration to generate the corresponding command.

    • Click the Run Command运行命令.png button to open Cloud Shell and quickly debug the command.

    • Click the Copy复制.png button to copy the CLI example. You can then paste it into a local shell and run the command.

      • When pasting the CLI example into a local shell, ensure that the parameter format is correct. For more information about parameter formats for Alibaba Cloud CLI commands, see Parameter formats.

      • OpenAPI Explorer automatically adds the --region option to the command, which overrides the default region in your credentials or environment variables. Remove this option if it is not needed.

Call an API

The Alibaba Cloud CLI uses the following syntax to call an RPC API operation:

aliyun <product> <APIName> [--parameter1 value1 --parameter2 value2 ...]
  • product: The product code of the target cloud service. For example, the product code for MongoDB is dds.

  • APIName: The API operation to call. For example, to create a replica set instance, call CreateDBInstance.

  • --parameter: The request parameters of the API operation.

Create a VPC

For information about the CreateVpc parameters, see CreateVpc.

Example:

aliyun vpc CreateVpc --RegionId cn-hangzhou

Sample output:

{
        "RequestId": "E8410523-E996-5345-9E4D-35D6C47A****",
        "ResourceGroupId": "rg-acfmz7u4zzr****",
        "RouteTableId": "vtb-bp1dcxc8j4jys18id****",
        "VRouterId": "vrt-bp1w2lsqfm9f7k2dy****",
        "VpcId": "vpc-bp191olzz22cgl073****"
}

Create a vSwitch

For information about the CreateVSwitch parameters, see CreateVSwitch.

Example:

aliyun vpc CreateVSwitch --ZoneId cn-hangzhou-i --CidrBlock 172.16.1.0/24 --VpcId vpc-bp191olzz22cgl073****

Sample output:

{
        "RequestId": "D3316995-CAB6-58A3-97E5-F1CBFE2E****",
        "VSwitchId": "vsw-bp10cm6ujv0na2vlp****"
}

Create a MongoDB instance

For information about the CreateDBInstance parameters, see CreateDBInstance.

Example:

aliyun dds CreateDBInstance --RegionId cn-hangzhou --ZoneId cn-hangzhou-i --EngineVersion 7.0 --DBInstanceClass mdb.shard.4x.large.d --DBInstanceStorage 20 --VpcId vpc-bp191olzz22cgl073**** --VSwitchId vsw-bp10cm6ujv0na2vlp****

Sample output:

{
        "DBInstanceId": "dds-bp1df136c811****",
        "OrderId": "23705179664****",
        "RequestId": "1336E68C-86A4-5355-A12A-D0A0C27A****"
}