Connecting to a Yandex StoreDoc cluster from applications
You can connect to a Yandex StoreDoc cluster using command line tools, graphical IDEs, and Docker containers. To learn how to connect from your application code, see Code examples.
In the examples below, the root.crt SSL certificate is located in the following directory:
~/.mongodb/for Ubuntu.$HOME\.mongodbfor Windows.
If the connection to the cluster is successful and the test query is executed, the name of the database to which the connection was made will be displayed.
Command line tools
To see code examples with the host FQDN filled in, open the cluster page in the management console
The setup method depends on whether cluster sharding is enabled:
Linux (Bash)
Before connecting, install the MongoDB Shell utility.
For a non-sharded cluster:
mongosh --norc \
--tls \
--tlsCAFile ~/.mongodb/root.crt \
--host '<Yandex_StoreDoc_host_1_FQDN>:27018,...,<Yandex_StoreDoc_host_N_FQDN>:27018' \
--username <DB_username> \
--password <DB_user_password> \
<DB_name>
For a sharded cluster:
mongosh --norc \
--tls \
--tlsCAFile ~/.mongodb/root.crt \
--host '<MONGOINFRA_or_MONGOS_host_1_FQDN>:27017,...,<MONGOINFRA_or_MONGOS_host_N_FQDN>:27017' \
--username <DB_username> \
--password <DB_user_password> \
<DB_name>
For a non-sharded cluster:
mongosh --norc \
--ssl \
--sslCAFile ~/.mongodb/root.crt \
--host '<Yandex_StoreDoc_host_1_FQDN>:27018,...,<Yandex_StoreDoc_host_N_FQDN>:27018' \
--username <DB_username> \
--password <DB_user_password> \
<DB_name>
For a sharded cluster:
mongosh --norc \
--ssl \
--sslCAFile ~/.mongodb/root.crt \
--host '<MONGOINFRA_or_MONGOS_host_1_FQDN>:27017,...,<MONGOINFRA_or_MONGOS_host_N_FQDN>:27017' \
--username <DB_username> \
--password <DB_user_password> \
<DB_name>
For a non-sharded cluster:
mongosh --norc \
--host '<Yandex_StoreDoc_host_1_FQDN>:27018,...,<Yandex_StoreDoc_host_N_FQDN>:27018' \
--username <DB_username> \
--password <DB_user_password> \
<DB_name>
For a sharded cluster:
mongosh --norc \
--host '<MONGOINFRA_or_MONGOS_host_1_FQDN>:27017,...,<MONGOINFRA_or_MONGOS_host_N_FQDN>:27017' \
--username <DB_username> \
--password <DB_user_password> \
<DB_name>
To learn how to get host FQDN, see this guide.
Once connected, run the db command.
Windows (PowerShell)
Before connecting, install the MongoDB Shell utility.
For a non-sharded cluster:
mongosh.exe --norc `
--host '<Yandex_StoreDoc_host_1_FQDN>:27018,...,<Yandex_StoreDoc_host_N_FQDN>:27018' `
--tls `
--tlsCAFile $HOME\.mongodb\root.crt `
--username <DB_username> `
--password <DB_user_password> `
<DB_name>
For a sharded cluster:
mongosh.exe --norc `
--host '<MONGOINFRA_or_MONGOS_host_1_FQDN>:27017,...,<MONGOINFRA_or_MONGOS_host_N_FQDN>:27017' `
--tls `
--tlsCAFile $HOME\.mongodb\root.crt `
--username <DB_username> `
--password <DB_user_password> `
<DB_name>
For a non-sharded cluster:
mongosh.exe --norc `
--host '<Yandex_StoreDoc_host_1_FQDN>:27018,...,<Yandex_StoreDoc_host_N_FQDN>:27018' `
--username <DB_username> `
--password <DB_user_password> `
<DB_name>
For a sharded cluster:
mongosh.exe --norc `
--host '<MONGOINFRA_or_MONGOS_host_1_FQDN>:27017,...,<MONGOINFRA_or_MONGOS_host_N_FQDN>:27017' `
--username <DB_username> `
--password <DB_user_password> `
<DB_name>
To learn how to get host FQDN, see this guide.
Once connected, run the db command.
Connecting from graphical IDEs
Connections were tested in the following environment:
- MacOS Big Sur 11.3
- JetBrains DataGrip:
2021.1 - DBeaver Enterprise:
21.0
You can only use graphical IDEs to connect to public cluster hosts with an SSL certificate.
To avoid connection errors, save the certificate
DataGrip
- Create a data source:
- Select File → New → Data Source → MongoDB.
- On the General tab:
-
Configure the connection as follows:
-
User, Password: DB user name and password.
-
URL: Connection string.
For a non-sharded cluster:
mongodb://<Yandex_StoreDoc_host_1_FQDN>:27018,..,<Yandex_StoreDoc_host_N_FQDN>:27018/<DB_name>For a sharded cluster:
mongodb://<MONGOINFRA_or_MONGOS_host_1_FQDN>:27017,...<MONGOINFRA_or_MONGOS_host_N_FQDN>:27017/<DB_name>To learn how to get host FQDN, see this guide.
-
-
Click Download to download the connection driver.
-
- On the SSH/SSL tab:
- Enable Use SSL.
- In the CA file field, specify the path to the file with an SSL certificate for the connection.
- Click Test Connection. If the connection is successful, you will see the connection status and information about the DBMS and driver.
- Click OK to save the data source.
DBeaver
Connections to Yandex StoreDoc clusters are only available in DBeaver business editions
To connect to your cluster:
- Create a new DB connection:
- In the Database menu, select New connection.
- Select MongoDB from the DB list.
- Click Next.
- Specify the connection parameters on the Main tab:
-
Under Address, change Type to
URLand specify the connection string.For a non-sharded cluster:
mongodb://<Yandex_StoreDoc_host_1_FQDN>:27018,..,<Yandex_StoreDoc_host_N_FQDN>:27018/<DB_name>For a sharded cluster:
mongodb://<MONGOINFRA_or_MONGOS_host_1_FQDN>:27017,...<MONGOINFRA_or_MONGOS_host_N_FQDN>:27017/<DB_name>To learn how to get host FQDN, see this guide.
-
In the Device list, select
SCRAM-SHA-256(type of password encryption when connecting to the DB). -
Under Authentication, specify the DB username and password.
-
- On the SSL tab:
- Enable Use SSL.
- In the Root certificate field, specify the path to the saved SSL certificate file.
- Under Settings, select Skip hostname validation.
- Click Test connection .... If the connection is successful, you will see the connection status and information about the DBMS and driver.
- Click Ready to save the database connection settings.
Before you connect from a Docker container
To connect to a Yandex StoreDoc cluster from a Docker container using SSL, add the following lines to the Dockerfile:
RUN apt-get update && \
apt-get install wget --yes && \
mkdir --parents ~/.mongodb && \
wget "https://storage.yandexcloud.net/cloud-certs/CA.pem" \
--output-document ~/.mongodb/root.crt && \
chmod 0644 ~/.mongodb/root.crt
To connect without SSL, no additional Dockerfile settings are required.
After you run the Docker container, navigate to it and install mongosh. You will need it to connect to the cluster.