MongoDB CLI provides a command-line interface for managing your MongoDB Cloud Manager projects and clusters.
This tutorial demonstrates how to:
Create clusters in your Cloud Manager project
Retrieve details about the new cluster
The reference pages for the commands mentioned in this tutorial are available in the MongoDB CLI Commands.
Prerequisites
Before you begin, complete the following tasks:
Ensure that your environment is compatible
Create a Cloud Manager organization
Generate Programmatic API Keys that have: - The
project owneror higher role - The access list entry for your IP address or CIDR range
Create a Cluster
Use the mongocli cloud-manager clusters create command to create a cluster in Cloud Manager.
The following command creates a sample cluster with the following settings:
Cluster name:
getStartedMongoDB server version:
5.0.0Feature compatibility version:
5.0Replica set members:
3Member hostnames:
host1,host2,host3Note
This tutorial uses the hostnames
host1,host2, andhost3. Replace these hostnames with valid MongoDB server hostnames.Data directories for each
mongodinstance:/data/cluster/rs1,/data/cluster/rs2,/data/cluster/rs3Log file path for each
mongodinstance:/data/cluster/rs1/mongodb.log,/data/cluster/rs2/mongodb.log,/data/cluster/rs3/mongodb.logPort for each
mongodprocess:29010,29020,29030Voting priority for each member:
1Number of votes for each member:
1
Copy and paste the following cluster-wide and replica set configuration properties in a file named getStartedCluster.json.
To learn more about the configuration file properties, see Cluster Configuration File.
{ "name": "getStarted", "version": "5.0.0", "featureCompatibilityVersion": "5.0", "processes": [ { "hostname": "host1", "dbPath": "/data/cluster/rs1", "logPath": "/data/cluster/rs1/mongodb.log", "priority": 1, "votes": 1, "port": 29010 }, { "hostname": "host2", "dbPath": "/data/cluster/rs2", "logPath": "/data/cluster/rs2/mongodb.log", "priority": 1, "votes": 1, "port": 29020 }, { "hostname": "host3", "dbPath": "/data/cluster/rs3", "logPath": "/data/cluster/rs3/mongodb.log", "priority": 1, "votes": 1, "port": 29030 } ] }
Retrieve the Cluster
You can check whether your cluster was successfully created by retrieving the cluster details using the mongocli cloud-manager clusters describe command.
mongocli cloud-manager cluster describe getStarted
Your command output should look similar to the following:
{ "mongoURI": "mongodb://host1:29010,host2:29020,host3:29030", "name": "getStarted", "processes": [ { "buildIndexes": true, "db_path": "/data/cluster/rs1", "featureCompatibilityVersion": "5.0", "hostname": "host1", "log_path": "/data/cluster/rs1/mongodb.log", "name": "getStartedCluster", "port": 29010, "priority": 1, "process_type": "mongod", "slave_delay": 0, "version": "5.0.0", "votes": 1, "arbiter_only": false, "disabled": false, "hidden": false }, { "buildIndexes": true, "db_path": "/data/cluster/rs2", "featureCompatibilityVersion": "5.0", "hostname": "host2", "log_path": "/data/cluster/rs2/mongodb.log", "name": "getStartedCluster", "port": 29020, "priority": 1, "process_type": "mongod", "slave_delay": 0, "version": "5.0.0", "votes": 1, "arbiter_only": false, "disabled": false, "hidden": false }, { "buildIndexes": true, "db_path": "/data/cluster/rs3", "featureCompatibilityVersion": "5.0", "hostname": "host3", "log_path": "/data/cluster/rs3/mongodb.log", "name": "getStartedCluster", "port": 29030, "priority": 1, "process_type": "mongod", "slave_delay": 0, "version": "5.0.0", "votes": 1, "arbiter_only": false, "disabled": false, "hidden": false } ] }
Watch Your Automation Configuration Status
Run the mongocli cloud-manager automation watch command to determine if the cluster is ready for use. The following command uses the default profile to access the Cloud Manager project:
mongocli cm automation watch
Summary
Congratulations! You have successfully created a cluster to host your
data. You can connect to your cluster using the connection
string for
mongosh or your application or view your cluster by logging
in to the UI.