If you have ever installed Mongo 3.* version and worrying as to how to upgrade it to Mongo 4.x. Then this story is for you, Mongo has made the upgrades comparatively easy. This story is a brief overview as to how to upgrade Mongo and it is divided into three segments
While Migrating Databases from one node to another using
mongodump --host sourcehost:27017 --db client_c_n --archive | mongorestore --host targethost:27017 --archive
- We landed into
Unrecognized field 'snapshot'. mongo
this error.
We saw that there is a version mismatch as in source host being 4.2.x
and target being 3.6.17
between both the mongo servers.
Now we have to take an immediate step to upgrade mongo and maintain the same version of mongo across the nodes.
Please note that you can update mongo DB only on Stepwise. For instance, 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.
- Get the FeatureCompatibilityVersion
- Set the FeatureCompatibilityVersion
- Upgrade to the next stable version
- Enter mongo shell and then type
db.adminCommand( { getParameter: 1, featureCompatibilityVersion: 1 } )
if the parameter is set you should be seeing a result similar to this"featureCompatibilityVersion" : { "version" : "3.6" }
- If not then go ahead and set the featureCompatibilityVersion as follows
db.adminCommand( { setFeatureCompatibilityVersion: "<current_version>" } )
- Exit the shell
- Once the parameter is set we are all set to upgrade our DB
- stop mongo using
systemctl stop mongod.service
- Download the tarball from mongodb
- untar and copy the binaries in
bin
directory to the place where existing binaries are present typically/usr/local/bin
or/bin
- Incase you want to check you can try
which mongodump
and it should point to the location where existing binaries are present.
- stop mongo using
- Now start the mongo
systemctl restart mongod.service
- Incase of any errors please check the log
/var/log/mongodb/mongod.log
- If you find nothing in the log then check
journalctl -xe
and also check if the permission are correctly given
- Always check versions on fellow nodes before deploying anything . If the change is a minor version change its ok but if its major change please try to stick to only one version :)