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 cluster name and select the Databases tab.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using 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 a list of clusters in the folder.
To get a list of cluster databases, use the list REST API method for the Database resource or the DatabaseService/List gRPC API call and provide the cluster ID in the clusterId
request parameter.
You can get the cluster ID with a list of clusters in the folder.
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 Add.
-
Enter the database name and click Add.
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. -
Authorize the appropriate cluster users for access to the database created.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using 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 a 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 a MongoDB cluster.
-
Add a
database
block to the Managed Service for MongoDB cluster description:resource "yandex_mdb_mongodb_cluster" "<cluster_name>" { ... database { 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
Timeouts
The Terraform provider sets the following timeouts for Managed Service for MongoDB cluster operations:
- Creating a cluster, including by restoring one from a backup: 30 minutes.
- Editing a cluster: 60 minutes.
Operations exceeding the set timeout are interrupted.
Add the timeouts
block to the cluster description, for example:
resource "yandex_mdb_mongodb_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # An hour and a half
update = "2h" # Two hours
}
}
To create a new database in a cluster, use the create REST API method for the Database resource or the DatabaseService/Create gRPC API call and provide the following in the request:
- ID of the cluster where you want to create a database, in the
clusterId
parameter. To retrieve the ID, get a list of clusters in the folder. - Database settings in the
databaseSpec
parameter.
To allow access to the created database, use the update REST API method for the User resource or the UserService/Update gRPC API call.
Deleting a database
- Go to the folder page
and select Managed Service for MongoDB. - Click the cluster name and open the Databases tab.
- Click the
icon in the same row as the DB and select Delete.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using 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 a 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 a MongoDB cluster.
-
Delete the
database
block with the DB name from the Managed Service for MongoDB cluster description. -
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
Timeouts
The Terraform provider sets the following timeouts for Managed Service for MongoDB cluster operations:
- Creating a cluster, including by restoring one from a backup: 30 minutes.
- Editing a cluster: 60 minutes.
Operations exceeding the set timeout are interrupted.
Add the timeouts
block to the cluster description, for example:
resource "yandex_mdb_mongodb_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # An hour and a half
update = "2h" # Two hours
}
}
To delete a database, use the delete REST API method for the Database resource or the DatabaseService/Delete gRPC API call and provide the following in the request:
- Cluster ID in the
clusterId
parameter. To find out the cluster ID, get a list of clusters in the folder. - Database name, in the
databaseName
parameter.
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.