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
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:
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:
path: C:\Program Files\MongoDB\Server\3.4\logs\mongo.log
dbPath: C:\Program Files\MongoDB\Server\3.4\data\db
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:
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:
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
If you want to import, backup, or restore databases or data into your MongoDB instance on a non-standard port using
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:
- Maintenance scripts (backups, logging)
- Creating custom MongoDB databases, collections, and documents