On MongoDB Master Slave Configuration
It’s pretty straight forward to setup a Master/Slave configuration for MongoDB. If you want to experiment on a single Windows box, use the steps below:
Start by creating the data directories:
c:\Users\John> cd c:\data
c:\data>mkdir masterdb
c:\data>mkdir slavedb1
c:\data>mkdir slavedb2
Startup the master database (I assume you’ve of course added Mongo’s bin directory to your path).
c:\>mongod --master --dbpath c:\data\mongodb
Startup the first slave. Make sure to change its port from something other than the default 27017 that’s being used by the master db! The source is the server name where master resides.
c:\>mongod --slave --port 27018 --source localhost --dbpath c:\data\slavedb1
The other slaves may be setup the same way.
c:\>mongod --slave --port 27019 --source localhost --dbpath c:\data\slavedb2
c:\>mongod --slave --port 27020 --source localhost --dbpath c:\data\slavedb3
To confirm that that replication is working, connect to the master.
c:\>mongo localhost/MongoTunes
>db.Artists.insert({ Name : "Radiohead" })
Now connect to one of the slaves.
c:\>mongo localhost:27019/MongoTunes
> db.Artists.find()
{ "_id" : ObjectId("4c4eef2b84610000000035f6"), "Name" : "Radiohead" }
You should see the Artist document you inserted in the master. If you don’t, run the find again… If you’ve setup a few slaves, there might be a delay.
More advanced configuration is available at http://www.mongodb.org/display/DOCS/Master+Slave




