Running MongoDB 2 and 3 on the same computer

Manually install (untar) MongoDB 2 and 3 into two different folders, for example

.../mongodb2
.../mongodb3

Create log and data folders for each version

.../mongodb2/log
.../mongodb2/data 
.../mongodb3/log
.../mongodb3/data

Create a conf file for each version.

.../mongodb2/data/mongod.conf
.../mongodb3/data/mongod.conf

Contents of these files can be something like

logpath=.../mongodb2/log/mongod.log
port=27017
dbpath=.../mongodb2/data
pidfilepath=.../mongodb2/mongod.pid

logpath=.../mongodb3/log/mongod.log
port=37017
dbpath=.../mongodb3/data
pidfilepath=.../mongodb3/mongod.pid

As you can see here, MongoDB 2 will be running on port 27017 and MongoDB 3 will be running on port 37017

No start each server with the following commands

.../mongodb2/bin/mongod  --config .../mongodb2/mongod.conf
.../mongodb3/bin/mongod  --config .../mongodb3/mongod.conf

That’s it 🙂

Two different command line clients can be run as follows

.../mongodb2/bin/mongo --port 27017
.../mongodb3/bin/mongo --port 37017

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s