Sitecore MongoDB Blog Series: How to Setup Multiple Instances of MongoDB on the Same Server

Posted by

If you are like me and have multiple Sitecore solutions installed on your development machine, it might be necessary to run two different versions of MongoDB to support each version of Sitecore.

Background: I have an “older” Sitecore 8.0.4 Sitecore solution running locally on MongoDB 2.6. I also have a Sitecore site 8.2.2 which uses MongoDB 3.4. While technically I could just migrate the 2.6 databases to 3.4, I prefer to mimic the current production environment for the older Sitecore site.

A Note on MongoDB 2.6

MongoDB 2.6 is past end of life and is no longer supported by MongoDB. While technically Sitecore 8.2 supports MongoDB 2.6, there are known compatibility issues.

You should definitely use at least MongoDB 3.0 to make use of the new WiredTiger storage engine, which delivers 7-10x greater throughput for write-intensive applications, such as Sitecore.

Use Configuration Files

Setting up two or more instances of MongoDB on the same machine is easy. All we have to do is setup the appropriate settings when starting the MongoDB service. I recommend using a configuration file to make this easy.

To get started, create a “config” folder in your new MongoDB installation root folder. Then create a new empty text file:

C:\Program Files\MongoDB\Server\3.4\config\mongod-3.4.cfg

In this file, paste in the following snippet. Then make sure to change the log file location, database location, and the port for your particular installation:

destination: file
path: C:\Program Files\MongoDB\Server\3.4\logs\mongo.log

dbPath: C:\Program Files\MongoDB\Server\3.4\data\db

port: 27018

Then to actually install MongoDB via mongod.exe you simply pass this config file location as a command line parameter:

mongod --config="C:\Program Files\MongoDB\Server\3.4\config\mongod-3.4.cfg" --install --serviceName="MongoDB 3.4" --serviceDisplayName="MongoDB 3.4"

The MongoDB service installer will read your config file and install the service with the specified name:

mongodb multiple instances

Repeat this process for all instances of MongoDB you want to install on your machine.

If your current instance is installed without a config file, or if you do not have a version specific service name, I recommend uninstalling the service and reinstalling your service with the above config file method. Doing so will ensure all installations are consistent.

Connecting to MongoDB on a Non Standard Port

Okay, so you installed your second MongoDB instance, but how do you connect to it?

Sitecore Connection Strings

Just change or append the port to your Sitecore connection strings:


Mongo Shell

To launch mongo shell on a non standard port, simply add the port as a command line parameter:

mongo --port 27018

If you leave off the port, it will connect to the instance with the default port 27017.

If you want to import, backup, or restore databases or data into your MongoDB instance on a non-standard port using mongodump.exe, mongorestore.exe or mongoimport.exe, you must specify the port when running the command in the same manor as above. Easy!


This one is really easy. Simply make sure to change the default port when creating or editing your connection:

robomongo new connection

Coming Up:

  • Maintenance scripts (backups, logging)
  • Creating custom MongoDB databases, collections, and documents

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s