Database replication with MongoDB is easy to setup. Replication duplicates
all of the data from a master to one or more slave instances and allows for
safety and quick recovery in case of a problem with your master database.
Here is an example of how quick and easy it is to test out replication in
MongoDB. Create a couple of directories for holding your mongo databases.
mkdir master slave
cd master
mongod --master --dbpath .
cd slave
mongod --slave --port 27018 --dbpath . --source localhost
mongo
db.person.save( {name:'Geoff Lane'} )
db.person.save( {name:'Joe Smith'} )
db.person.find()
db.person.save( {name:'Jim Johnson', age: 65} )
db.person.find()
mongo --port 27018
db.person.find()
the db.person.find()
returns all of the values
that were saved in the master list as well which shows that replication is
working. One of the other interesting facts is that you can start a slave
instance even after the mongod master is already running and has data and all
of the data will be replicated over to the slave instance as well. This all
works without ever shutting down your mongod master instance. This allows you
to add replication after the fact with no downtime. For more on MongoDB check
out these books:
* MongoDB: The Definitive Guide
* The Definitive Guide to MongoDB: The NoSQL Database for Cloud and Desktop Computing
* MongoDB for Web Development (Developer's Library)