How to upgrade MongoDB on Linux Cloud Servers

2020-07-02 By Sam 13874 Views linux mongodb development
0 reviews

MongoDB is a document-oriented NoSQL database and it is used for high volume data storage. MongoDB uses collections and documents instead of tables and rows as in traditional relational databases.


This guide outlines the basic steps required to upgrade the MongoDB on Linux systems.


CentOS 7 / 8

  1. Before upgrading the MongoDB, suggest taking the necessary backups. Create the backup of the current MongoDB data with the below command.

    # cp -r /var/lib/mongodb /var/lib/mongodb.backup
    

    mongodbupgrade1

  2. To check the current version of the MongoDB on the server

    # mongod --version
    

    mongodbupgrade2

  3. Before proceeding with the upgrade, stop the MongoDB service.

    # systemctl stop mongod
    

    mongodbupgrade3

  4. Here using the package manager to upgrade the MongoDB to the latest version 4.2. So, create the file /etc/yum.repos.d/mongodb-org-4.2.repo to know yum where the latest MongoDB packages and add the below details, and then save.

    [mongodb-org-4.2]
    name=MongoDB Repository
    baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
    gpgcheck=1
    enabled=1
    gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
    

    mongodbupgrade4

  5. Now run the below command to install the latest version of MongoDB.

    # yum install mongodb-org
    

    mongodbupgrade5

  6. Run the below command to check the version of MongoDB and verify whether it is upgraded.

    # mongod --version
    

    mongodbupgrade6


Ubuntu / Debian

  1. Before Upgrading the MongoDB, suggest taking the necessary backups. Create the backup of the current MongoDB data with the below command.

    # cp -r /var/lib/mongodb /var/lib/mongodb.backup
    

    mongodbupgrade7

  2. To check the current version of MongoDB on the server.

    # mongod --version
    

    mongodbupgrade8

  3. Before proceeding with the upgrade, stop the MongoDB service.

    # systemctl stop mongod
    

    mongodbupgrade9

  4. Run the below command to import the MongoDB public GPG Key.

    # apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
    

    mongodbupgrade10

  5. Now remove the old list using the below command.

    # rm /etc/apt/sources.list.d/mongodb-org-3.2.list
    

    mongodbupgrade11

  6. Here using the package manager to upgrade the MongoDB to version 3.4. So, create the file /etc/apt/sources.list.d/mongodb-org-3.4.list and add the below details.

    deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse
    

    mongodbupgrade12

    NOTE: Replace the ubuntu xenial with your distribution name and release.

  7. Now update the server with the below command.

    # apt-get update
    

    mongodbupgrade13

  8. Once the server is updated, then proceed with the MongoDB installation.

    # apt-get install -y mongodb-org
    

    mongodbupgrade14

  9. Run the below command to check the version of MongoDB and verify whether it is upgraded.

    # mongod --version
    

    mongodbupgrade15


Related Tutorials

What do you think about this article?

Rate this article
LayerStack Promotion
Need assistance?

Try this guide to receive free bundled services at signup on a new free account.

Sign Up

Your Feedback Is Important

We hope you’ll give the new products and updates a try. If you have an idea for improving our products or want to vote on other user ideas so they get prioritized, please submit your feedback on our Community platform. And if you have any questions, please feel free to ask in the Community or contact our Technical Support team.