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>
To learn how to get host FQDN, see this guide.
Once connected, run the db command.
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>
To learn how to get host FQDN, see this guide.
Once connected, run the db command.
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.
mongosh "mongodb+srv://<DB_user_name>:<DB_user_password>\
@<cluster_ID>.mdb.yandexcloud.net/<DB_name>"
You can get the cluster ID with the list of clusters in the folder.
Once connected, run the db command.
You can add connection parameters to the command, if required, for example:
tls: Enables TLS encryption for the connection (trueorfalse). Encryption is enabled by default.tlsCAFile: Path to the.pemfile with root certificates from the CA.readPreference: Hosts to read from:primary: Only the primary replica (master).primaryPreferred: Master or secondary replicas if the master is unavailable.secondary: Only secondary replicas.secondaryPreferred: Secondary replicas or the master if there are no secondary replicas.nearest: Least lagging host.
authSource: Name of the database storing the user credentials. By default, it is the same as<DB_name>.appName: App name to display in logs.
For more information about available connection parameters, see this reference
The parameter string begins with the ? character, and & is the separator.
Example of a command with connection properties:
mongosh "mongodb+srv://user********:qwe********@c9qng7jhsgtg********.mdb.yandexcloud.net\
/db********?authSource=admin&appName=debug"
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>
To learn how to get host FQDN, see this guide.
Once connected, run the db command.
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.
mongosh.exe "mongodb+srv://<DB_user_name>:<DB_user_password>`
@<cluster_ID>.mdb.yandexcloud.net/<DB_name>"
You can get the cluster ID with the list of clusters in the folder.
Once connected, run the db command.
You can add connection parameters to the command, if required, for example:
tls: Enables TLS encryption for the connection (trueorfalse). Encryption is enabled by default.tlsCAFile: Path to the.pemfile with root certificates from the CA.readPreference: Hosts to read from:primary: Only the primary replica (master).primaryPreferred: Master or secondary replicas if the master is unavailable.secondary: Only secondary replicas.secondaryPreferred: Secondary replicas or the master if there are no secondary replicas.nearest: Least lagging host.
authSource: Name of the database storing the user credentials. By default, it is the same as<DB_name>.appName: App name to display in logs.
For more information about available connection parameters, see this reference
The parameter string begins with the ? character, and & is the separator.
Example of a command with connection properties:
mongosh.exe "mongodb+srv://user********:qwe********@c9qng7jhsgtg********.mdb.yandexcloud.net`
/db********?authSource=admin&appName=debug"
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 download the connection 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 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 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 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 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.