Source: http://blog.chenlb.com/2010/03/mongodb-master-slave.html
MongoDB master-slave replication is similar to MySQL.
Add the -- master option on the master server to start the instance.
Bin/mongod -- dbpath =/home/MongoDB/DB -- master -- oplogsize 64
-- Oplogsize indicates the operation log, which is smaller than 64 MB.
Add the -- slave option to the server to start and specify the Master Address.
Bin \ mongod.exe -- dbpath = G: \ MongoDB \ dB -- slave -- source 192.168.0.2 -- only test -- slavedelay 10
-- Only refers to the replication of this database, for example, test, -- source is the Master Address, -- slavedelay refers to the interval between replication detection, version 1.4 has no effect, I used 10 s, but I detected it once in 2 s.
Add some data to the master server. Open the client
Bin/Mongo
> DB. Foo. Save ({"ID": 123, "name": 'chenlb '})
If the operation succeeds, you can view the data on the server:
Bin/Mongo
> DB. Foo. Find ({"ID": 123 })
Official Address: http://www.mongodb.org/display/DOCS/Replication