MongoDB – Replica Set

Here’s a good tutorial on Replica-Set on MongoDB website

In this tutorial, in “Replication” section tutorial asks to create a document on PRIMARY server.{name: "ReplSet Tutorial"});

After creating a document on PRIMARY if you hit


in MongoDB shell the result is displayed. But if you switch to SECONDARY and execute same command to check if replication is working, you get following error.

uncaught exception: error: { "$err" : "not master and slaveok=false", "code" : 13435 }

The reason is stated here :

So all you need to do is hit this command


That’s it. Now “db.messages.find()” should work on SECONDARY as well.



One thought on “MongoDB – Replica Set

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s