Tag Archives: replica set

MongoDB – Replica Set

Here’s a good tutorial on Replica-Set on MongoDB website http://www.mongodb.org/display/DOCS/Replica+Set+Tutorial

In this tutorial, in “Replication” section tutorial asks to create a document on PRIMARY server.

db.messages.save({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 : http://www.mongodb.org/display/DOCS/Querying#Querying-slaveOk

So all you need to do is hit this command


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