Now Hiring: Are you a driven and motivated 1st Line DevOps Support Engineer?

How to Upgrade MongoDB from 6.0 to 7.0 on Ubuntu 22.04 – Step-by-Step Guide

a-blog-cover-image-for-a-technical-artic_jYIxbi0KS_qn8RoFATS6ng_ZpqWTyDXQtKe-XwbvZuThg
Tech Articles

How to Upgrade MongoDB from 6.0 to 7.0 on Ubuntu 22.04 – Step-by-Step Guide

Introduction

MongoDB is a popular NoSQL database used by developers and enterprises around the world for its scalability, flexibility, and ease of use. With each major version, MongoDB introduces new features, performance optimizations, and security enhancements.

The release of MongoDB 7.0 includes several critical improvements such as:

  • Better performance under high-concurrency workloads
  • Enhanced aggregation pipeline capabilities
  • Improved observability and diagnostics
  • New security features and default settings

If you’re currently using MongoDB 6.x on Ubuntu 22.04, upgrading to version 7.0 ensures you’re taking advantage of the latest features and long-term support from MongoDB.

This step-by-step guide will help you safely upgrade MongoDB from 6.0 to 7.0 without data loss, using official MongoDB repositories and best practices..

1. Prerequisites

Ubuntu 22.04 LTS

MongoDB 6.x already installed

Sudo/root access


2. Step 1: Stop the MongoDB Service

Before upgrading, stop the MongoDB daemon to prevent any data corruption:

sudo systemctl stop mongod

3. Step 2: Remove MongoDB 6.x Packages

Purge the old MongoDB 6.x version and clean the system:

sudo apt purge -y mongodb-org*
sudo apt autoremove -y
sudo apt clean

4. Step 3: Add the MongoDB 7.0 APT Repository

Download and add the MongoDB 7.0 public GPG key:

curl -fsSL https://pgp.mongodb.com/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor

Then add the MongoDB 7.0 repository to your sources list:

echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

5. Step 4: Update Package Index

Refresh your package list to load the new MongoDB 7.0 repo:

sudo apt update

6. Step 5: Install MongoDB 7.0 (Specific Version)

Install MongoDB 7.0 with exact version control to avoid accidental upgrades later:

sudo apt install -y \
mongodb-org=7.0.21 \
mongodb-org-server=7.0.21 \
mongodb-org-shell=7.0.21 \
mongodb-org-mongos=7.0.21 \
mongodb-org-tools=7.0.21 \
mongodb-org-database=7.0.21 \
mongodb-org-database-tools-extra=7.0.21

7. Step 6: Start MongoDB Service

Now start the MongoDB service again:

sudo systemctl start mongod

To enable it to auto-start on boot (optional):

sudo systemctl enable mongod

8. Step 7: Verify the MongoDB Version

Check that MongoDB 7.0 is successfully installed:

mongod --version

9. Expected Output:

db version v7.0.21

10.Done!

You’ve successfully upgraded MongoDB from 6.0 to 7.0 on Ubuntu 22.04!

Final Tips:

Always back up your database before upgrades (mongodump).

Check MongoDB 7.0 release notes for breaking changes.

Monitor logs after upgrade using journalctl -u mongod.

Writen By Abu Sufyan

Leave your thought here

Your email address will not be published. Required fields are marked *