Skip to content

Instantly share code, notes, and snippets.

@rohitjoshixyz
Last active June 4, 2020 15:00
Show Gist options
  • Select an option

  • Save rohitjoshixyz/c89fe8fe02b28dcfc519e41490c98ce4 to your computer and use it in GitHub Desktop.

Select an option

Save rohitjoshixyz/c89fe8fe02b28dcfc519e41490c98ce4 to your computer and use it in GitHub Desktop.
Upgrading mongodb for simply smart from version 3.2 to 4.2.7

Upgrading mongodb for simply smart from version 3.2 to 4.2.7:

Step 0: Take dump of current database

mongodump --db simplysmart_api_development --out /home/rohit/Desktop/dump

Step 1: After installing a mongodb version(initally 3.2)

cd Desktop/softwares

mongod --dbpath='/home/rohit/Desktop/softwares/simplysmart_api_development'

mongorestore -d 'simplysmart_api_development' '/home/rohit/Desktop/softwares/simplysmart_api_development'

Check if you are able to access db records in rails console.

Step 2(optional):

Uninstall version 3.2:

sudo service mongod stop

sudo apt-get purge mongodb-org*

sudo rm -r /var/log/mongodb

sudo rm -r /var/lib/mongodb

NOTE: To upgrade from a version earlier than the 3.6-series, you must successively upgrade major releases until you have upgraded to 3.6-series. For example, if you are running a 3.4-series, you must upgrade first to 3.6 before you can upgrade to 4.0. It holds true for all versions.

Step 3: Start upgrading

Upgrade to version 3.4: Follow instructions on the following install link. If you have 3.2 installed, it will get upgraded

https://docs.mongodb.com/v3.4/tutorial/install-mongodb-on-ubuntu/

Follow step 1

https://docs.mongodb.com/manual/release-notes/3.4-upgrade-standalone/ for reference

Upgrade to version 3.6:

https://docs.mongodb.com/v3.6/tutorial/install-mongodb-on-ubuntu/

Use the command that say install specific version of mongodb, it will upgrade mongodb from 3.4 to 3.6

Repeat step 1

This link helped me configure my mongodb https://hevodata.com/blog/install-mongodb-on-ubuntu/ to use start and stop CLI

Upgrade to 4.0:

Follow instructions on the following install link. It will get upgraded

https://docs.mongodb.com/v4.0/installation

https://docs.mongodb.com/manual/release-notes/4.0-upgrade-standalone/ for reference

Note: Use the command in the tab that say install specific version of mongodb, it will upgrade mongodb from 3.6 to 4.0.X

Make sure you check value of

db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )

and then run

db.adminCommand( { setFeatureCompatibilityVersion: "3.6" } )

in mongo shell against admin database after installing version 4.0

Repeat Step 1

If service isn't starting using our --dbpath, and still showing FCV error then delete current db files and extract db files again from the dump

Upgrade to 4.2:

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

Use the commad that say install specific version of mongodb, it will upgrade mongodb from 4.0 to 4.2.

https://docs.mongodb.com/manual/release-notes/4.2-upgrade-standalone/ for reference

Make sure you check

db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )

and run

db.adminCommand( { setFeatureCompatibilityVersion: "4.0" } )

or set it to 4.2 if you want to use latest features but it makes downgrading later complicated.

Step 5: Restore the database

mongorestore -d 'simplysmart_api_development' '/home/rohit/Desktop/dump/simplysmart_api_development' (db name should be same)

Tip: When doing this on production if you are unable to start mongod daemon for setting the featureCompatibilityVersion in the mongo shell, create a new folder and run sudo mongod --dbpath '/path/to/new_folder' and then open mongo shell in another terminal and set the featureCompatibilityVersion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment