Getting started with Managed Service for MongoDB
To get started with the service:
Getting started
-
Go to the management console
and log in to Yandex Cloud or sign up if not signed up yet. -
If you do not have a folder yet, create one:
-
In the management console
, select the appropriate cloud from the list on the left. -
At the top right, click Create folder.
-
Enter the folder name. The naming requirements are as follows:
- The name must be from 3 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter and the last character cannot be a hyphen.
-
(Optional) Enter a description of the folder.
-
Select Create a default network. This will create a network with subnets in each availability zone. Within this network, a default security group will be created, inside which all network traffic is allowed.
-
Click Create.
-
-
Make sure your account has the vpc.user role and the managed-mongodb.editor role or higher for creating a cluster.
-
You can connect to DB clusters from both inside and outside Yandex Cloud:
-
To connect to a DB cluster from inside Yandex Cloud, create a VM in the same cloud network as the DB cluster (with Linux).
-
To connect to the cluster from the internet, request public access to hosts when creating the cluster.
Note
The next step assumes that you connect to the cluster from a Linux-based VM.
-
-
Connect to the VM over SSH.
-
Install MongoDB Shell:
cd ~/ && \ wget https://repo.mongodb.org/apt/ubuntu/dists/focal/mongodb-org/4.4/multiverse/binary-amd64/mongodb-org-shell_4.4.1_amd64.deb && \ sudo dpkg -i mongodb-org-shell_4.4.1_amd64.deb
Create a cluster
- In the management console
, select the folder where you want to create a DB cluster. - Select Managed Service for MongoDB.
- Click Create cluster.
- Set the cluster parameters and click Create cluster. For more information, see Creating clusters.
- Wait until the cluster is ready: its status on the Managed Service for MongoDB dashboard will change to Running and its state, to Alive. This may take some time.
Connect to the DB
-
If you are using security groups for a cloud network, configure them to enable all relevant traffic between the cluster and the connecting host.
-
Get an SSL certificate:
Linux (Bash)/macOS (Zsh)Windows (PowerShell)mkdir -p ~/.mongodb && \ wget "https://storage.yandexcloud.net/cloud-certs/CA.pem" \ --output-document ~/.mongodb/root.crt && \ chmod 0644 ~/.mongodb/root.crt
The certificate will be saved to the
~/.mongodb/root.crt
file.mkdir $HOME\.mongodb; curl.exe -o $HOME\.mongodb\root.crt https://storage.yandexcloud.net/cloud-certs/CA.pem
The certificate will be saved to the
$HOME\.mongodb\root.crt
file.Corporate policies and antivirus software can block the download of certificates. For more information, see FAQ.
-
Connect to the cluster using the MongoDB CLI:
mongo --norc \ --ssl \ --sslCAFile ~/.mongodb/root.crt \ --host '<FQDN_of_MongoDB_host_1>:27018,...,<FQDN_of_MongoDB_host_N>:27018' \ --username <DB_username> \ --password <DB_user_password> \ <DB_name>
To learn how to get a host FQDN, see this guide.
What's next
- Read about service concepts.
- Learn more about creating a cluster and connecting to the database.
- Read questions and answers.