MongoDB 3.6 has some awesome features, change streams being my personal favourite (see all the changes here), but what if we have an old MongoDB cluster running on 3.4 and want to use these cool features? Here is how!
Note: This guide assumes you installed MongoDB from the package management system as seen here or as a replica set as seen here.
Upgrading MongoDB 3.4 to 3.6 on Ubuntu 16.04
Step 1: Stop the old Mongod server
Easy just run “sudo systemctl stop mongod” and MongoDB will be stopped.
Step 2: Import the MongoDB public key
Run “sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5” and the key is imported for you!
Step 3: Update the list file for apt/MongoDB
To remove the old list run “sudo rm /etc/apt/sources.list.d/mongodb-org-3.4.list”
Now add the new one with
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
Run “sudo apt-get update” to update apt’s lists.
Step 4: Upgrade the MongoDB install
The easiest way to do this is to run “sudo apt-get upgrade -y” which will make apt update all the out of date packages in your system. Fun!
If it asks to replace the file at /etc/mongod.conf just say no to keep your settings as they are.
Step 5: Start MongoDB
Run “sudo systemctl start mongod” and we are up and running. It’s as easy as that!
Just like that, you have a MongoDB 3.6 install working! This works for replica set’s as well, just upgrade each node in turn!
Until next time
Coffee to Code