Connecting to a Yandex StoreDoc cluster from applications
You can connect to a Yandex StoreDoc cluster using command line tools, graphical IDEs, or Docker containers. For details on connecting from your application code, see Code examples.
In the following examples, we assume that the root.crt SSL certificate is located in one of these directories:
~/.mongodb/for Ubuntu$HOME\.mongodbfor Windows
After you successfully connect to the cluster and run a test query, you will see the name of the database you connected to.
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 sharding is enabled in the cluster:
Linux (Bash)
Before connecting, install MongoDB Shell.
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_user_name> \
--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_user_name> \
--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_user_name> \
--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_user_name> \
--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_user_name> \
--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_user_name> \
--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 MongoDB Shell.
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_user_name> `
--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_user_name> `
--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_user_name> `
--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_user_name> `
--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
From graphical IDEs, you can only connect to public cluster hosts using 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: Database 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 get the database driver.
-
- On the SSH/SSL tab:
- Enable Use SSL.
- In the CA file field, specify the path to the SSL certificate for your connection.
- Click Test Connection. If the connection is successful, you will see the connection status, DBMS information, and driver details.
- Click OK to save the data source.
DBeaver
Connections to Yandex StoreDoc clusters are only available in DBeaver commercial editions
To connect to your cluster:
- Create a new database connection:
- In the Database menu, select New connection.
- Select MongoDB from the database list.
- Click Next.
- On the Main tab, specify the connection settings:
-
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 the
SCRAM-SHA-256password encryption type for the connection. -
Under Authentication, specify the database user name and password.
-
- On the SSL tab:
- Enable Use SSL.
- In the Root certificate field, specify the path to your saved SSL certificate file.
- Under Settings, check Skip hostname validation.
- Click Test connection .... If the connection is successful, you will see the connection status, DBMS information, and driver details.
- 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 over SSL, add the following lines to your 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 configuration is required.
After starting the Docker container, access it and install mongosh, which you will need to connect to the cluster.