Managing databases in Managed Service for MongoDB
You can add and remove databases, as well as view information about them.
Getting a list of cluster databases
- Go to the folder page
and select Managed Service for MongoDB. - Click the name of the cluster you need and select the Databases tab.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through the --folder-name
or --folder-id
parameter.
To get a list of databases in a cluster, run the command:
yc managed-mongodb database list
--cluster-name <cluster_name>
You can request the cluster name with the list of clusters in the folder.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the Database.List method and send the following request, e.g., via cURL
:curl \ --request GET \ --header "Authorization: Bearer $IAM_TOKEN" \ --url 'https://mdb.api.cloud.yandex.net/managed-mongodb/v1/clusters/<cluster_ID>/databases'
You can request the cluster ID with the list of clusters in the folder.
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the DatabaseService.List call and send the following request, e.g., via gRPCurl
: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.List
You can request the cluster ID with the list of clusters in the folder.
-
View the server response to make sure the request was successful.
Creating a database
Note
You can create a maximum of 1000 databases in each cluster.
-
Go to the folder page
and select Managed Service for MongoDB. -
Click the cluster name.
-
Select the Databases tab.
-
Click Create database.
-
Enter 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_internal
are reserved for Managed Service for MongoDB. You cannot create DBs with these names. -
Assign roles to allow access to the created database to the appropriate cluster users.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through the --folder-name
or --folder-id
parameter.
Run the create database command and set the name of the new database:
yc managed-mongodb database create <DB_name>
--cluster-name <cluster_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
, and mdb_internal
are reserved for Managed Service for MongoDB. You cannot create DBs with these names.
You can request the cluster name with the list of clusters in the folder.
Managed Service for MongoDB runs the create database operation.
Authorize the appropriate cluster users for access to the database created.
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
Add the
yandex_mdb_mongodb_database
resource:resource "yandex_mdb_mongodb_database" "<DB_name>" { cluster_id = "<cluster_ID>" name = "<DB_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_internal
are reserved for Managed Service for MongoDB. You cannot create DBs with these names. -
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the Database.Create method and send the following request, e.g., via cURL
: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>" } }'
Where
databaseSpec
is the object containing the new DB 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_internal
are reserved for Managed Service for MongoDB. You cannot create DBs with these names.You can request the cluster ID with the list of clusters in the folder.
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the DatabaseService.Create call and send the following request, e.g., via gRPCurl
: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>" } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mongodb.v1.DatabaseService.Create
Where
database_spec
is the object containing the new DB 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_internal
are reserved for Managed Service for MongoDB. You cannot create DBs with these names.You can request the cluster ID with the list of clusters in the folder.
-
View the server response to make sure the request was successful.
Deleting a database
- Go to the folder page
and select Managed Service for MongoDB. - Click the cluster name and open the Databases tab.
- Click
in the row with the DB you need and select Delete.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through the --folder-name
or --folder-id
parameter.
To delete a database, run the command:
yc managed-mongodb database delete <DB_name>
--cluster-name <cluster_name>
You can request the cluster name with the list of clusters in the folder.
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
Delete the
yandex_mdb_mongodb_database
resource with the name of the database you want to delete. -
Make sure the settings are correct.
-
Using the command line, navigate to the folder that contains the up-to-date Terraform configuration files with an infrastructure plan.
-
Run the command:
terraform validate
If there are errors in the configuration files, Terraform will point to them.
-
-
Confirm updating the resources.
-
Run the command to view planned changes:
terraform plan
If the resource configuration descriptions are correct, the terminal will display a list of the resources to modify and their parameters. This is a test step. No resources are updated.
-
If you are happy with the planned changes, apply them:
-
Run the command:
terraform apply
-
Confirm the update of resources.
-
Wait for the operation to complete.
-
-
For more information, see the Terraform provider documentation
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Use the Database.Delete method and send the following request, e.g., via cURL
: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 request the cluster ID with the list of clusters in the folder, and the DB name, with the list of DBs in the cluster.
-
View the server response to make sure the request was successful.
-
Get an IAM token for API authentication and put it into the environment variable:
export IAM_TOKEN="<IAM_token>"
-
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapi
Below, we assume the repository contents are stored in the
~/cloudapi/
directory. -
Use the DatabaseService.Delete call and send the following request, e.g., via gRPCurl
: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.Delete
You can request the cluster ID with the list of clusters in the folder, and the DB name, with the list of DBs in the cluster.
-
View the server response to make sure the request was successful.
Warning
Before creating a new database with the same name, wait for the delete operation to complete, otherwise the database being deleted will be restored. Operation status can be obtained with a list of cluster operations.