> For the complete documentation index, see [llms.txt](https://circleci.com/docs/llms.txt)

# Upgrade MongoDB

MongoDB is a database service used by CircleCI Server. This page describes how to upgrade MongoDB from version `3.6.22` to `7.0.15`.

MongoDB `3.6.22` is shipped with CircleCI Server 4.9.

## Upgrade MongoDB to 4.4

### Prerequisites

*   Ensure backups have been taken. You need a backup of MongoDB to restore in case anything goes wrong during the upgrade progress.
    
*   You are able to modify your `values.yaml` file.
    
*   `helm upgrade` works from your system to upgrade the cluster.
    
*   Your MongoDB root password is available.
    

### Scripted upgrade

We have created a shell script that you can use to upgrade your cluster’s MongoDB instance [here](https://github.com/CircleCI-Public/server-scripts/tree/main/upgrade-mongo-to-4.4).

Alternatively, you can use the following instructions to manually upgrade your cluster’s MongoDB:

### Manual upgrade

#### 1\. Upgrade from MongoDB 3.6 to 4.0

1.  Your `values.yaml` contains the following snippet:
    
    `````````
    mongodb:
      image:
        tag: 3.6.22-debian-9-r38
    `````````
    
    To begin the upgrade process, change the tag to `4.0.27-debian-9-r118`:
    
    `````````
    mongodb:
      image:
        tag: 4.0.27-debian-9-r118
    `````````
    
2.  Run `helm upgrade` to update your installation.
    
3.  Once the `helm upgrade` has completed and MongoDB has rolled, you will need to `exec` into the pod (with the root password handy) to modify the compatibility version. Be sure to replace `<password>` with your MongoDB root password.
    
    `````````
    $ kubectl exec -it mongodb-0 -- mongo -u root -p <password>
    db.adminCommand( { setFeatureCompatibilityVersion: "4.0" } )
    `````````
    
4.  You will receive a `{ "ok" : 1 }` response from MongoDB. Exit out of the MongoDB shell and pod.
    

#### 2\. Upgrade from MongoDB 4.0 to 4.2

1.  Change the tag to `4.2.21-debian-10-r8`:
    
    `````````
    mongodb:
      image:
        tag: 4.2.21-debian-10-r8
    `````````
    
2.  Run `helm upgrade` to update your installation.
    
3.  Once the `helm upgrade` has completed and MongoDB has rolled, you will need to `exec` into the pod (with the root password handy) to modify the compatibility version. Be sure to replace `<password>` with your MongoDB root password.
    
    `````````
    $ kubectl exec -it mongodb-0 -- mongo -u root -p <password>
    db.adminCommand( { setFeatureCompatibilityVersion: "4.2" } )
    `````````
    
4.  You will receive a `{ "ok" : 1 }` response from MongoDB again. Exit out of the shell and pod.
    

#### 3\. Upgrade from MongoDB 4.2 to 4.4

1.  Change the tag one more time to `4.4.15-debian-10-r8`:
    
    `````````
    mongodb:
      image:
        tag: 4.4.15-debian-10-r8
    `````````
    
2.  Run `helm upgrade` to update your installation.
    
3.  Once the `helm upgrade` has completed and MongoDB has rolled, you will need to `exec` into the pod (with the root password handy) to modify the compatibility version. Be sure to replace `<password>` with your MongoDB root password.
    
    `````````
    $ kubectl exec -it mongodb-0 -- mongo -u root -p <password>
    db.adminCommand( { setFeatureCompatibilityVersion: "4.4" } )
    `````````
    
4.  Once you receive `{ "ok" : 1 }`, you have successfully upgraded your MongoDB to 4.4.15.
    

## Upgrade MongoDB to 7.0

### Prerequisites

*   You have completed the `4.4.15` upgrade above.
    
*   Ensure backups have been taken. You need a backup of MongoDB to restore in case anything goes wrong during the upgrade progress.
    
*   You are able to modify your `values.yaml` file.
    
*   `helm upgrade` works from your system to upgrade the cluster.
    
*   Your MongoDB root password is available.
    

### Scripted upgrade

We have created a shell script that you can use to upgrade your cluster’s MongoDB instance [here](https://github.com/CircleCI-Public/server-scripts/tree/main/upgrade-mongo-to-7.0).

Alternatively, you can use the following instructions to manually upgrade your cluster’s MongoDB:

### Manual upgrade

#### 1\. Upgrade from MongoDB 4.4 to 5.0

1.  Your `values.yaml` contains the following snippet:
    
    `````````
    mongodb:
      image:
        tag: 4.4.15-debian-10-r8
    `````````
    
    To begin the upgrade process, change the tag to `5.0.24-debian-11-r20` and update the probes to use `mongosh`:
    
    `````````
    mongodb:
      image:
        tag: 5.0.24-debian-11-r20
      livenessProbe:
        enabled: false
      readinessProbe:
        enabled: false
      customLivenessProbe:
        exec:
          command:
            - mongosh
            - --eval
            - "db.adminCommand('ping')"
        initialDelaySeconds: 30
        periodSeconds: 10
        timeoutSeconds: 5
        successThreshold: 1
        failureThreshold: 6
      customReadinessProbe:
        exec:
          command:
            - bash
            - -ec
            - |
              mongosh --eval 'db.hello().isWritablePrimary || db.hello().secondary' | grep -q 'true'
        initialDelaySeconds: 5
        periodSeconds: 10
        timeoutSeconds: 5
        successThreshold: 1
        failureThreshold: 6
    `````````
    
2.  Run `helm upgrade` to update your installation.
    
3.  Once the `helm upgrade` has completed and MongoDB has rolled, you will need to `exec` into the pod (with the root password handy) to modify the compatibility version. Note that MongoDB 5.0+ uses `mongosh` instead of `mongo`. Be sure to replace `<password>` with your MongoDB root password.
    
    `````````
    $ kubectl exec -it mongodb-0 -- mongosh -u root -p <password>
    db.adminCommand( { setFeatureCompatibilityVersion: "5.0" } )
    `````````
    
4.  You will receive a `{ "ok" : 1 }` response from MongoDB. Exit out of the MongoDB shell and pod.
    

#### 2\. Upgrade from MongoDB 5.0 to 6.0

1.  Change the tag to `6.0.13-debian-11-r21` while being sure to keep the new `customLivenessProbe` and `customReadinessProbe` parameters.:
    
    `````````
    mongodb:
      image:
        tag: 6.0.13-debian-11-r21
    `````````
    
2.  Run `helm upgrade` to update your installation.
    
3.  Once the `helm upgrade` has completed and MongoDB has rolled, you will need to `exec` into the pod (with the root password handy) to modify the compatibility version. Be sure to replace `<password>` with your MongoDB root password.
    
    `````````
    $ kubectl exec -it mongodb-0 -- mongosh -u root -p <password>
    db.adminCommand( { setFeatureCompatibilityVersion: "6.0" } )
    `````````
    
4.  You will receive a `{ "ok" : 1 }` response from MongoDB again. Exit out of the shell and pod.
    

#### 3\. Upgrade from MongoDB 6.0 to 7.0

1.  Change the tag to `7.0.15-debian-12-r2`:
    
    `````````
    mongodb:
      image:
        tag: 7.0.15-debian-12-r2
    `````````
    
2.  Run `helm upgrade` to update your installation.
    
3.  Once the `helm upgrade` has completed and MongoDB has rolled, you will need to `exec` into the pod (with the root password handy) to modify the compatibility version. Be sure to replace `<password>` with your MongoDB root password.
    
    MongoDB 7.0+ upgrade is one-way and cannot be downgraded.
    
    MongoDB 7.0+ requires the `confirm: true` parameter.
    
    `````````
    $ kubectl exec -it mongodb-0 -- mongosh -u root -p <password>
    db.adminCommand( { setFeatureCompatibilityVersion: "7.0", confirm: true } )
    `````````
    
4.  Once you receive `` { "ok" : 1 }` ``, you have successfully upgraded your MongoDB to 7.0.15.