top of page

MongoDB upgrade on Windows

Client’s requirements:

Case #1: Stand-alone server with the old version 3.2.12

Case #2: Replica set with even number of servers (2) on the same geolocation (Holland) with an arbiter installed on Azure with the old versions 3.2.12.

Servers hostnames (for demonstration only):

nl1primary

nl2secondary

az1arbiter

 

MongoDB stand-alone server’s upgrade (case #1)

  • Download MongoDB Community server 64-bit (last version, at the time of writing it’s 3.4.4) as *.msi file to each server.

  • On each replica set member it’s recommended to install the same version of MongoDB.

  • Create a new folder on each server for MongoDB binaries and configuration file.

  • Create configuration file and place it in an appropriate folder (usually installation folder): mongod.cfg (as a simple text file and change it’s extention). Of course, it’s possible to do it by batch.

  • Configure the configuration file with necessary options (with the path to the same data directory) and custom options you need:

systemLog:

destination: file

path: D:\data\log\mongod.log

storage:

dbPath: D:\data\db

engine: wiredTiger

net:

port: 27017 # or 30000 on arbiter only

etc.

  • Install MongoDB Community server through GUI or by batch with customized installation folder:

> msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.4.4-signed.msi INSTALLLOCATION="D:\MongoDB.3.4.4" ADDLOCAL="all"

  • Stop the MongoDB service with version 3.2.12:

> net stop MongoDB

  • Remove the old MongoDB service:

> "D:\MongoDB.3.2.12\bin\mongod.exe" –remove

  • Install a new MongoDB service before starting the server in command prompt (run as administrator):

> sc.exe create MongoDB binPath= "\"D:\MongoDB.3.4.4\bin\mongod.exe\" --service --config=\"D:\ MongoDB.3.4.4\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"

or

> "D:\MongoDB.3.4.4\bin\mongod.exe" --config "D:\MongoDB.3.4.4\mongod.cfg" --install

  • Start MongoDB service:

> net start MongoDB

Check in Services that this service is in “Running” status.

  • Connect to the server through command prompt and check the version:

> "C:\Program Files\MongoDB\Server\3.4\bin\mongo.exe"

> db.version()

  • Uninstall the old binaries and delete the previous installation folder if it’s necessary.

 

MongoDB replica set’s upgrade (case #2)

Arbiter

  • Remove the arbiter from the replica set - run on primary:

PRIMARY> rs.remove(“az1arbiter:30000”)

PRIMARY> rs.status()

  • Download MongoDB Community server 64-bit (last version, at the time of writing it’s 3.4.4) as *.msi file to each server.

On each replica set member it’s recommended to install the same version of MongoDB.

  • Create a new folder on the server for MongoDB binaries and configuration file.

  • Copy the existing configuration file and place it in an appropriate folder (usually installation folder): mongod.cfg (as a simple text file and change it’s extention). Of course, it’s possible to do it by batch.

  • Install MongoDB Community server through GUI or by batch with customized installation folder:

> msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.4.4-signed.msi INSTALLLOCATION="D:\MongoDB.3.4.4" ADDLOCAL="all"

  • Stop the MongoDB service with version 3.2.12:

> net stop MongoDB

  • Remove the old MongoDB service:

> "D:\MongoDB.3.2.12\bin\mongod.exe" –remove

  • Install a new MongoDB service before starting the server in command prompt (run as administrator):

> sc.exe create MongoDB binPath= "\"D:\MongoDB.3.4.4\bin\mongod.exe\" --service --config=\"D:\ MongoDB.3.4.4\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"

or

> "D:\MongoDB.3.4.4\bin\mongod.exe" --config "D:\MongoDB.3.4.4\mongod.cfg" –install

  • Delete line of replication from the copied file mongod.cfg and save this change.

  • Start MongoDB service:

> net start MongoDB

Check in Services that this service is in “Running” status.

  • Connect to the server through command prompt and check the version:

> "C:\Program Files\MongoDB\Server\3.4\bin\mongo.exe"

> db.version()

  • Stop the new service.

  • Change the file mongod.cfg – add a replication lines and save the file.

  • Start the new service.

  • Add the arbiter to the replica – run this command on primary:

PRIMARY> rs.add( { _id: 5, host : "az1arbiter:30000",arbiterOnly: true, priority: 1 } )

  • Check replica status:

ARBITER> rs.status()

  • Test a failover.

  • Uninstall the old binaries and delete the previous installation folder if it’s necessary.

Secondary

  • Download MongoDB Community server 64-bit (last version, at the time of writing it’s 3.4.4) as *.msi file to each server.

On each replica set member it’s recommended to install the same version of MongoDB.

  • Create a new folder on the server for MongoDB binaries and configuration file.

  • Copy the existing configuration file and place it in an appropriate folder (usually installation folder): mongod.cfg (as a simple text file and change it’s extention). Of course, it’s possible to do it by batch.

  • Install MongoDB Community server through GUI or by batch with customized installation folder:

> msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.4.4-signed.msi INSTALLLOCATION="D:\MongoDB.3.4.4" ADDLOCAL="all"

  • Stop the MongoDB service with version 3.2.12:

> net stop MongoDB

  • Remove the old MongoDB service:

> "D:\MongoDB.3.2.12\bin\mongod.exe" –remove

  • Install a new MongoDB service before starting the server in command prompt (run as administrator):

> sc.exe create MongoDB binPath= "\"D:\MongoDB.3.4.4\bin\mongod.exe\" --service --config=\"D:\ MongoDB.3.4.4\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"

or

> "D:\MongoDB.3.4.4\bin\mongod.exe" --config "D:\MongoDB.3.4.4\mongod.cfg" –install

  • Start MongoDB service:

> net start MongoDB

Check in Services that this service is in “Running” status.

  • Connect to the server through command prompt and check the version:

> "C:\Program Files\MongoDB\Server\3.4\bin\mongo.exe"

> db.version()

  • Check replica status on primary and on secondary:

PRIMARY> rs.status()

SECONDARY> rs.status()

  • Test a failover.

  • Uninstall the old binaries and delete the previous installation folder if it’s necessary.

Primary

  • Download MongoDB Community server 64-bit (last version, at the time of writing it’s 3.4.4) as *.msi file to each server.

On each replica set member it’s recommended to install the same version of MongoDB.

  • Create a new folder on the server for MongoDB binaries and configuration file.

  • Copy the existing configuration file and place it in an appropriate folder (usually installation folder): mongod.cfg (as a simple text file and change it’s extention). Of course, it’s possible to do it by batch.

  • Install MongoDB Community server through GUI or by batch with customized installation folder:

> msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.4.4-signed.msi INSTALLLOCATION="D:\MongoDB.3.4.4" ADDLOCAL="all"

  • Step down the replica set primary:

PRIMARY> rs.stepDown()

  • Check replica set status and validate a new primary server:

SECONDARY> rs.status()

PRIMARY> rs.status() # New primary server

  • Stop the MongoDB service with version 3.2.12:

> net stop MongoDB

  • Remove the old MongoDB service:

> "D:\MongoDB.3.2.12\bin\mongod.exe" –remove

  • Install a new MongoDB service before starting the server in command prompt (run as administrator):

> sc.exe create MongoDB binPath= "\"D:\MongoDB.3.4.4\bin\mongod.exe\" --service --config=\"D:\ MongoDB.3.4.4\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"

or

> "D:\MongoDB.3.4.4\bin\mongod.exe" --config "D:\MongoDB.3.4.4\mongod.cfg" –install

  • Start MongoDB service:

> net start MongoDB

Check in Services that this service is in “Running” status.

  • Connect to the server through command prompt and check the version:

> "C:\Program Files\MongoDB\Server\3.4\bin\mongo.exe"

> db.version()

  • Check replica status on primary and on secondary:

PRIMARY> rs.status()

SECONDARY> rs.status()

  • Uninstall the old binaries and delete the previous installation folder if it’s necessary.

 

Remarks:

  • Pay attention to a driver compatibility changes (applicative driver) in order to be able to use the various new features and upgrade to a driver version that supports these features because it’s necessary.

  • Upgrading from version 3.2 remains the compatibility level on 3.2 as default until you will change it manually.

It is recommended that after upgrading, you allow your deployment to run without enabling these features for a while to ensure the likelihood of downgrade is minimal. When you are confident that the likelihood of downgrade is minimal, change the compatibility level:

PRIMARY> db.adminCommand( { setFeatureCompatibilityVersion: “3.4” } )

  • If after removing the old 3.2.12 service you see that this server is in status “disabled” restart Windows Server and validate that the service was completely removed.

  • If you cannot start standalone MongoDB (not a member of replica set!) and get system error #1067, check if the file mongod.lock has a size greater than 0 KB - it means the file isn’t empty and has integer value (it can be result of unexpected shutdown). In this case you need repair a database in the following way:

  • Backup your data (mongodump or the whole data directory).

  • Run repair batch:

"D:\MongoDB.3.4.4\bin\mongod.exe" --config "D:\MongoDB.3.4.4\mongod.cfg" –repair

  • Start the service:

> net start MongoDB

 

Good luck!

Featured Posts
Check back soon
Once posts are published, you’ll see them here.
Recent Posts
Archive
Search By Tags
No tags yet.
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square
bottom of page