MongoDB version upgrade
You can only upgrade your Managed Service for MongoDB cluster to a version that immediately follows the current one, such as 4.2 to 4.4. Upgrades to higher versions are performed in steps. For example, for MongoDB, the upgrade sequence from version 4.2 to 6.0 is: 4.2 → 4.4 → 5.0 → 6.0.
Alert
After upgrading, you cannot roll a cluster back to the previous version.
Before a version upgrade
Make sure this does not affect your applications:
- See the MongoDB changelog
to check how updates might affect your applications. - Try upgrading the version on a test cluster. You can deploy it from a backup of the main cluster.
- Create a backup of the main cluster directly before the version upgrade.
Upgrading a cluster
- Go to the folder page
and select Managed Service for MongoDB. - Select the cluster from the list and click Edit.
- In the Version field, select a new version number.
- Click Save changes.
As soon as you run the upgrade, the cluster enters the UPDATING status. Wait for the operation to complete and then check the cluster version.
-
Get a list of your MongoDB clusters using this command:
yc managed-mongodb cluster list
-
Get information about the cluster you need and check the MongoDB version in the
config.version
parameter:yc managed-mongodb cluster get <cluster_name_or_ID>
-
Run the MongoDB upgrade:
yc managed-mongodb cluster update <cluster_name_or_ID> \ --mongodb-version=<new_version_number>
As soon as you run the upgrade, the cluster enters the UPDATING status. Wait for the operation to complete and then check the cluster version.
-
After the upgrade, all MongoDB features that are not backward-compatible with the previous version will be disabled. To remove this restriction, run this command:
yc managed-mongodb cluster update <cluster_name_or_ID> \ --feature-compatibility-version=<new_version_number>
Learn more about backward compatibility in the MongoDB documentation
.
-
Open the current Terraform configuration file with an infrastructure plan.
For more information about creating this file, see Creating clusters.
-
To the Managed Service for MongoDB cluster description, add the
version
field or change its value if it is already there:resource "yandex_mdb_mongodb_cluster" "<cluster_name>" { ... cluster_config { version = "<MongoDB_version>" } }
-
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.
How do I change these limits?
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 update the MongoDB version, use the update REST API method for the Cluster resource or the ClusterService/Update 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. - MongoDB version which you are upgrading to, in the
configSpec.version
parameter. - List of settings to update (in this case,
configSpec.version
), in theupdateMask
parameter.
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 updateMask
parameter as a single comma-separated string.
After the upgrade, all MongoDB features that are not backward-compatible with the previous version will be disabled. To remove this restriction, use the update API method and provide the new version number in the call using the configSpec.featureCompatibilityVersion
property.
Learn more about backward compatibility in the MongoDB documentation
Examples
Let's assume that you need to upgrade your cluster from version 5.0 to version 6.0.
-
To find out the cluster ID, get a list of all clusters in the folder:
yc managed-mongodb cluster list
Result:
+----------------------+---------------+---------------------+--------+---------+ | ID | NAME | CREATED AT | HEALTH | STATUS | +----------------------+---------------+---------------------+--------+---------+ | c9q8p8j2gaih******** | mongodb406 | 2019-04-23 12:44:17 | ALIVE | RUNNING | +----------------------+---------------+---------------------+--------+---------+
-
To get information about the
c9qut3k64b2o********
cluster, run the following command:yc managed-mongodb cluster get c9qut3k64b2o********
Result:
id: c9qut3k64b2o******** folder_id: b1g0itj57rbj******** created_at: "2019-07-16T09:43:50.393231Z" name: mongodb406 environment: PRODUCTION monitoring: - name: Console description: Console charts link: https://console.yandex.cloud/folders/b1g0itj57rbj********/managed-mongodb/cluster/c9qut3k64b2o********?section=monitoring config: version: "5.0" feature_compatibility_version: "5.0" ...
-
To upgrade the
c9qutgkd4b2o********
cluster to version 6.0, run this command:yc managed-mongodb cluster update c9qutgkd4b2o******** \ --mongodb-version=6.0
-
To enable all 6.0 features in the
c9qutgkd4b2o********
cluster, run this command:yc managed-mongodb cluster update c9qutgkd4b2o******** \ --feature-compatibility-version=6.0