Managing databases in Yandex StoreDoc
You can add and remove databases, as well as view their details.
Getting a list of cluster databases
- In the management console
, select a folder. - Navigate
to Yandex StoreDoc. - Click the name of your cluster and select the Databases tab.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.
If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
To get a list of cluster databases, run this command:
yc managed-mongodb database list
--cluster-name <cluster_name>
You can get the cluster name with the list of clusters in the folder.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Database.List method, e.g., via the following cURL
request:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-mongodb/v1/clusters/<cluster_ID>/databases'You can get the cluster ID from the list of clusters in your folder.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the DatabaseService.List method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mongodb/v1/database_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mongodb.v1.DatabaseService.ListYou can get the cluster ID with the list of clusters in the folder.
-
Check the server response to make sure your request was successful.
Getting database info
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.
If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
To get information about a specific database:
-
See the description of the CLI command for getting database info:
yc managed-mongodb database get --help -
Get database info by running this command:
yc managed-mongodb database get <DB_name> \ --cluster-id=<cluster_ID>You can get the database name with the list of databases in the cluster, and the cluster ID, with the list of clusters in the folder.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Database.Get method, e.g., via the following cURL
request:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-mongodb/v1/clusters/<cluster_ID>/databases/<DB_name>'You can get the cluster ID with the list of clusters in the folder, and the database name, with the list of databases in the cluster.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the DatabaseService.Get method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mongodb/v1/database_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "database_name": "<DB_name>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mongodb.v1.DatabaseService.GetYou can get the cluster ID with the list of clusters in the folder, and the database name, with the list of databases in the cluster.
-
Check the server response to make sure your request was successful.
Creating a database
Note
You can create a maximum of 1000 databases in each cluster.
-
In the management console
, select a folder. -
Navigate
to Yandex StoreDoc. -
Click the cluster name.
-
Select the Databases tab.
-
Click Create database.
-
Specify the database name and click Create.
A database name may contain Latin letters, numbers, underscores, and hyphens. The name may be up to 63 characters long. Such names as
config,local,admin, andmdb_internalare reserved for Yandex StoreDoc. You cannot create DBs with these names. -
Set up database protection against accidental deletion. The possible values are:
- Same as cluster
- Enabled
- Disabled
Deletion protection only works at the individual database level. Deleting a cluster will permanently remove all its databases, including those with deletion protection.
-
To grant access to the new database, assign the relevant roles to the required cluster users.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.
If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
To create a database in a cluster, run this command:
yc managed-mongodb database create <DB_name> \
--cluster-name <cluster_name> \
--deletion-protection=<protect_database_from_deletion>
Where:
-
<DB_name>: Database name.A database name may contain Latin letters, numbers, underscores, and hyphens. The name may be up to 63 characters long. Such names as
config,local,admin, andmdb_internalare reserved for Yandex StoreDoc. You cannot create DBs with these names. -
--cluster-name: Cluster name you can request with the list of clusters in the folder. -
--deletion-protection: Database protection from accidental deletion,trueorfalse. There is no default value; the database uses the one from the corresponding cluster setting. If the protection is on (true), you cannot delete the database.Deletion protection only works at the individual database level. Deleting a cluster will permanently remove all its databases, including those with deletion protection.
-
Open the current Terraform configuration file with the infrastructure plan.
To learn how to create this file, see Creating a cluster.
-
Add the
yandex_mdb_mongodb_databaseresource:resource "yandex_mdb_mongodb_database" "<DB_name>" { cluster_id = "<cluster_ID>" name = "<DB_name>" deletion_protection = <protect_database_from_deletion> }Where:
-
cluster_id: Cluster ID you can request with the list of clusters in the folder. -
name: Database name.A database name may contain Latin letters, numbers, underscores, and hyphens. The name may be up to 63 characters long. Such names as
config,local,admin, andmdb_internalare reserved for Yandex StoreDoc. You cannot create DBs with these names. -
--deletion-protection: Database protection from accidental deletion,trueorfalse. There is no default value; the database uses the one from the corresponding cluster setting. If the protection is on (true), you cannot delete the database.Deletion protection only works at the individual database level. Deleting a cluster will permanently remove all its databases, including those with deletion protection.
-
-
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm updating the resources.
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
For more information, see this Terraform provider guide.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Database.Create method, e.g., via the following cURL
request:curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-mongodb/v1/clusters/<cluster_ID>/databases' \ --data '{ "databaseSpec": { "name": "<DB_name>", "deletionProtection": <protect_database_from_deletion> } }'Where:
-
<cluster_ID>: Cluster ID you can request with the list of clusters in the folder. -
databaseSpec.name: Database name.A database name may contain Latin letters, numbers, underscores, and hyphens. The name may be up to 63 characters long. Such names as
config,local,admin, andmdb_internalare reserved for Yandex StoreDoc. You cannot create DBs with these names. -
databaseSpec.deletionProtection: Database protection from accidental deletion,trueorfalse. There is no default value; the database will use the one from the corresponding cluster setting. If the protection is on (true), you cannot delete the database.Deletion protection only works at the individual database level. Deleting a cluster will permanently remove all its databases, including those with deletion protection.
-
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the DatabaseService.Create method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mongodb/v1/database_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "database_spec": { "name": "<DB_name>", "deletion_protection": <protect_database_from_deletion> } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mongodb.v1.DatabaseService.CreateWhere:
-
cluster_id: Cluster ID you can request with the list of clusters in the folder. -
database_spec.name: Database name.A database name may contain Latin letters, numbers, underscores, and hyphens. The name may be up to 63 characters long. Such names as
config,local,admin, andmdb_internalare reserved for Yandex StoreDoc. You cannot create DBs with these names. -
database_spec.deletion_protection: Database protection from accidental deletion,trueorfalse. There is no default value; the database will use the one from the corresponding cluster setting. If the protection is on (true), you cannot delete the database.Deletion protection only works at the individual database level. Deleting a cluster will permanently remove all its databases, including those with deletion protection.
-
-
Check the server response to make sure your request was successful.
After you create a database, assign access permissions for it to correct cluster users.
Updating database settings
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.
If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
To update your database settings, run this command:
yc managed-mongodb database update <DB_name> \
--cluster-name <cluster_name> \
--deletion-protection=<protect_database_from_deletion>
Where:
<DB_name>: Database name you can request with the list of databases in the cluster.--cluster-name: Cluster name you can request with the list of clusters in the folder.--deletion-protection: Database protection from accidental deletion,trueorfalse. There is no default value; the database uses the one from the corresponding cluster setting. If the protection is on (true), you cannot delete the database.
-
Open the current Terraform configuration file with the infrastructure plan.
To learn how to create this file, see Creating a cluster.
-
Locate the
yandex_mdb_mongodb_databaseresource. -
To enable or disable user protection from accidental deletion, update the
deletion_protectionfield value:resource "yandex_mdb_mongodb_database" "<DB_name>" { ... deletion_protection = <protect_database_from_deletion> ... }Where
deletion_protectionis database protection from accidental deletion:trueorfalse. There is no default value; the database will use the one from the corresponding cluster setting. If the protection is on (true), you cannot delete the database. -
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm updating the resources.
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
For more information, see this Terraform provider guide.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Database.Update method, e.g., via the following cURL
request:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
updateMaskparameter as a single comma-separated string.curl \ --request PATCH \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-mongodb/v1/clusters/<cluster_ID>/databases/<DB_name>' \ --data '{ "updateMask": "deletionProtection", "deletionProtection": <protect_database_from_deletion> }'Where:
<cluster_ID>: Cluster name you can request with the list of clusters in the folder.<DB_name>: Database name you can request with the list of databases in the cluster.updateMask: Comma-separated string of settings to update.deletionProtection: Database protection from accidental deletion,trueorfalse. There is no default value; the database will use the one from the corresponding cluster setting. If the protection is on (true), you cannot delete the database.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the DatabaseService.Update method, e.g., via the following gRPCurl
request:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
update_maskparameter as an array ofpaths[]strings.Format for listing settings
"update_mask": { "paths": [ "<setting_1>", "<setting_2>", ... "<setting_N>" ] }grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mongodb/v1/database_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "database_name": "<DB_name>", "update_mask": { "paths": [ "deletion_protection" ] }, "deletion_protection": <protect_database_from_deletion> }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mongodb.v1.DatabaseService.UpdateWhere:
cluster_id: Cluster ID you can request with the list of clusters in the folder.database_name: Database name you can request with the list of databases in the cluster.update_mask: List of settings to update as an array of strings (paths[]).deletion_protection: Database protection from accidental deletion,trueorfalse. There is no default value; the database will use the one from the corresponding cluster setting. If the protection is on (true), you cannot delete the database.
-
Check the server response to make sure your request was successful.
Deleting a database
Note
Before you delete a database, disable its deletion protection.
- In the management console
, select a folder. - Navigate
to Yandex StoreDoc. - Click the name of your cluster and select the Databases tab.
- Click
in the relevant database row and select Delete.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id.
If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
To delete a database, run this command:
yc managed-mongodb database delete <DB_name>
--cluster-name <cluster_name>
You can get the cluster name with the list of clusters in the folder.
-
Open the current Terraform configuration file with the infrastructure plan.
To learn how to create this file, see Creating a cluster.
-
Remove the
yandex_mdb_mongodb_databaseresource with the name of the database you want to delete. -
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm updating the resources.
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
For more information, see this Terraform provider guide.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Call the Database.Delete method, e.g., via the following cURL
request:curl \ --request DELETE \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-mongodb/v1/clusters/<cluster_ID>/databases/<DB_name>'You can get the cluster ID from the list of clusters in your folder, and the database name from the list of databases in your cluster.
-
Check the server response to make sure your request was successful.
-
Get an IAM token for API authentication and put it into an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume that the repository contents reside in the
~/cloudapi/directory. -
Call the DatabaseService.Delete method, e.g., via the following gRPCurl
request:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mongodb/v1/database_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "database_name": "<DB_name>" }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mongodb.v1.DatabaseService.DeleteYou can get the cluster ID from the list of clusters in your folder, and the database name, from the list of databases in your cluster.
-
Check the server response to make sure your request was successful.
Warning
If you plan to create a new database with the same name, wait for the deletion to complete. Otherwise, the system will restore the original database. You can check the operation status in the list of cluster operations.