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 dele