Check the Results
Everything is configured, therefore now we have to ensure that master-slave replication works for our databases.
1. Access the master DB server via SSH again and connect to your database: mongo -u admin -p {admin_password} {DB_name}
use {DB_name}
2. Then run the following command in order to add a test record to your DB: db.{DB_name}.save( {mytestkey:"mytestvalue"} )
You’ll be shown the following output, informing that record is successfully added: WriteResult({ "nInserted" : 1 })
3. In addition, let’s verify that our test record exists: db.{DB_name}.find()
As a result, you’ll receive a line with an object ID and key/value you’ve specified: { "_id" : ObjectId("5405be9c430c1564c2551b3f"), "mytestkey" : "mytestvalue" }
Log out of the master base.
4. Now enter your slave MongoDB container and connect to the database similarly you did it for master: mongo -u admin -p {admin_password} {DB_name}
use {DB_name}
5. Run the same db.{DB_name}.find() command. As you can see, the newly added record has been successfully replicated to your slave database.