Getting started with Managed Service for MongoDB
To get started with the service:
Before you start
Go to the management console. Then log in to Yandex.Cloud or sign up if you don't have an account yet.
If you don't have a folder yet, create one:
Click Create folder in the Home page of the management console.
Enter the folder name.
- Length — from 3 to 63 characters.
- The name may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter. The last character can't be a hyphen.
Select Create a default network. A network is created with subnets in each availability zone.
You can connect to DB clusters from both inside and outside Yandex.Cloud:
- To connect from inside Yandex.Cloud, create a Linux- or Windows-based virtual machine in the same network as the DB cluster.
- To be able to connect to the cluster from the internet, request public access to hosts when creating the cluster.
The next step assumes that you connect to the cluster from a Linux-based VM.
Connect to the VM via 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 management console, select the folder where you want to create a cluster.
- Select Managed Service for MongoDB.
- Click Create cluster.
- Set the cluster parameters and click Create cluster. This process is described in detail in Creating MongoDB clusters.
- When the cluster is ready, its status changes to Running and its state to Alive. This may take some time.
Connect to the DB
Get an SSL certificate:
Create a folder:
$ mkdir ~/.mongodb
Get a certificate:
$ wget "https://storage.yandexcloud.net/cloud-certs/CA.pem" -O ~/.mongodb/root.crt
Configure permissions to the certificate:
$ chmod 0600 ~/.mongodb/root.crt
Connect to the cluster using the MongoDB CLI:
$ mongo --norc \ --ssl \ --sslCAFile ~/.mongodb/root.crt \ --host 'rs01/<address of host 1>:27018,<address of host 2>:27018,<address of host N>:27018' \ -u <user name> \ -p <user password> \ <DB name>