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.
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
To check the current version of the MongoDB on the server
# mongod --version
Before proceeding with the upgrade, stop the MongoDB service.
# systemctl stop mongod
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
Now run the below command to install the latest version of MongoDB.
# yum install mongodb-org
Run the below command to check the version of MongoDB and verify whether it is upgraded.
# mongod --version
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
To check the current version of MongoDB on the server.
# mongod --version
Before proceeding with the upgrade, stop the MongoDB service.
# systemctl stop mongod
Run the below command to import the MongoDB public GPG Key.
# apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
Now remove the old list using the below command.
# rm /etc/apt/sources.list.d/mongodb-org-3.2.list
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
NOTE: Replace the ubuntu xenial with your distribution name and release.
Now update the server with the below command.
# apt-get update
Once the server is updated, then proceed with the MongoDB installation.
# apt-get install -y mongodb-org
Run the below command to check the version of MongoDB and verify whether it is upgraded.
# mongod --version