Skip to content

Updating MongoDB 3.6 to 4.4

The following instructions include the update of both, single system and cluster.

Caution - incompatibility

Due to incompatibility of the MongoDB service versions 3.6 and 4.4 you must export the stored data before updating and reimport them afterwards.

The standard procedure is as follows:

  1. Save the database content

  2. Update the database

  3. Restore the database content


Saving the Database Content

  1. Open a shell.

  2. Start MongoDB, if necessary.

    sudo systemctl start mongod
    

    Hint - cluster

    In a cluster, make sure that all members of the replica set are running.

  3. Save the stored data:

    • Single server:

      mongodump --ssl --sslAllowInvalidCertificates --oplog --gzip --out /tmp/mongodump
      
    • Cluster:

      mongodump --uri="mongodb://<server1>:27017,<server2>:27017,<server3>:27017/?replicaSet=p5&readPreference=secondary" --ssl --sslAllowInvalidCertificates --oplog --gzip --out /tmp/mongodump
      

      Hint - cluster

      In a cluster, you need to perform the following instructions on one server only. The data will be read from one of the secondary cluster members. This will not affect the operation of the replica set primary.


Updating the Database

  1. Stop all dependent services.

    Hint - services with database access

    Services that access the database will restart continuously while you are updating the database. To prevent this unnecessary server load, you need to stop all services.

    Literature - further information

    Please refer to the documentations of the installed products for further information about stopping the corresponding services.

  2. Stop MongoDB

    sudo systemctl stop mongod
    
  3. Remove all subdirectories and files in the /opt/seal/data/seal-mongodb directory, except of the base directory itself.

    sudo rm -rf /opt/seal/data/seal-mongodb/*
    
  4. Install MongoDB.

  5. Reconfigure a shared replica set.

  6. On single systems or the replica set primary, reinitialize the database.

  7. Reconnect the database servers to the cluster.

  8. Check the status of the database.

Caution - update member of the replica set

Make sure that all cluster members are upgraded and reconfigured before you restore the database.


Restoring the Database Content

  1. Remove the directory of the admin database dump:

    sudo rm -rf /tmp/mongodump/admin
    

    Caution - admin database

    The admin database is used by MongoDB for storing internal configuration and runtime information. After the update, this information will no longer match the new configuration. Therefore, you must remove this directory before you restore the data.

  2. Restore the data:

    Single server:

    mongodump --tls --tlsAllowInvalidCertificates --drop --oplogReplay --gzip /tmp/mongodump
    

    Cluster:

    mongorestore --uri="mongodb://<server1>:27017,<server2>:27017,<server3>:27017/?replicaSet=p5" --tls --tlsInsecure --drop --oplogReplay --gzip /tmp/mongodump
    

    Hint - cluster

    In a cluster, you have to perform the following instructions on one server only.

  3. Restart all dependent services.

    Literature - further information

    Please refer to the documentations of the installed products for further information about stopping the corresponding services.


Back to top