-- Master slave Experiment
-- Create a data directory
$ Mkdir/data/1
$ Mkdir/data/2
$ Mkdir/data/3
-- Start the MongoDB Database
$/Data/mongodb-linux-i686-1.6.0/bin/mongod -- Port 27020 -- dbpath/data/1 -- master &
$/Data/mongodb-linux-i686-1.6.0/bin/mongod -- Port 27021 -- dbpath/data/2 -- master &
$/Data/mongodb-linux-i686-1.6.0/bin/mongod -- Port 27022 -- dbpath/data/3 -- slave &
-- Start the client
$/Data/mongodb-linux-i686-1.6.0/bin/Mongo localhost: 27020
$/Data/mongodb-linux-i686-1.6.0/bin/Mongo localhost: 27020
> Use db1
> DB. Foo. insert ({X: 1 })
> DB. Foo. insert ({X: 2 })
> Exit
$ # Master 2
$/Data/mongodb-linux-i686-1.6.0/bin/Mongo localhost: 27021
> Use DB2
> DB. Foo. insert ({X: 999, note: "in DB2 "})
> Exit
$ # Configure slave
$/Data/mongodb-linux-i686-1.6.0/bin/Mongo localhost: 27022
> Use local
> DB. Sources. insert ({Host: "localhost: 27020 "})
> DB. Sources. insert ({Host: "localhost: 27021 "})
> DB. Sources. Find ()
> // Wait a little, still connected to slave
> Use db1
> DB. Foo. Count ()
2
> Use DB2
> DB. Foo. Find ()
{& Quot; _ id & quot;: objectid (& quot; 4b8ed00a1d42d47b3afa3c47 & quot;), & quot; X & quot;: 999, & quot; Note & quot;: & quot; in DB2 & quot "}
> DB. printslavereplicationinfo ()
========================================================== ========================================================== =====
-- Master experiment
-- Create a data directory
$ Mkdir/data/M1
$ Mkdir/data/m2
-- Start the server
$/Data/mongodb-linux-i686-1.6.0/bin/mongod -- Port 27017 -- dbpath/data/M1 -- master
$/Data/mongodb-linux-i686-1.6.0/bin/mongod -- slave -- master -- dbpath/data/slave -- port 10000 -- source localhost
-- Start the client
$/Data/mongodb-linux-i686-1.6.0/bin/Mongo localhost: 27017
> Z= connect ("localhost: 10000/test ")
> DB. Foo. insert ({X: 7 });
> Z. Foo. Find ()
> DB. Foo. Find ()
// Master and slave Data Synchronization
> DB. Foo. insert ({X: 81 });
> DB. Foo. Find ()
> Z. Foo. Find ()
// Master and slave Data Synchronization
> Z. Foo. insert ({X: 91 });
> DB. Foo. Find ()
> Z. Foo. Find ()
// The data is not synchronized here, And the DB cannot find data of x 9. Inconsistent with the log on http://www.mongodb.org/display/docs/master?master=replication
> Z. Foo. Remove ({X: 8 });
> DB. Foo. Find ()
> Z. Foo. Find ()
// If the data is not synchronized, the database returns the data of x 8. Inconsistent with the log on http://www.mongodb.org/display/docs/master?master=replication
[] Conclusion: The dB (master) can be synchronized to the slave, but the slave cannot be synchronized to the master. It is inconsistent with that in Doc.