Tag Archives: “not master and slaveok=false”

Mongodb’s “not master and slave = false” error and its solution

First of all this is normal because SECONDARY is not allowed to read and write. In applications with more writes and less reads, Replica Sets are used to achieve read and write separation. By specifying at connection time or specifying slaveOk in the master, the secondary shares the read pressure and the primary only takes on the write operations.

For secondary nodes in a replica set that are not readable by default, the

[mongodb@ligh bin]$ mongo 127.0.0.1:33333

MongoDB shell version: 2.0.1

connecting to: 127.0.0.1:33333/test

SECONDARY> db.user.find()

error: { “$err” : “not master and slaveok=false”, “code” : 13435 }

SECONDARY> db.getMongo()

connection to 127.0.0.1:33333

SECONDARY> db.getMongo().setSlaveOk();

not master and slaveok=false

Set slaveok=ok on the master

[mongodb@ligh bin]$ mongo 127.0.0.1:33333

MongoDB shell version: 2.0.1

connecting to: 127.0.0.1:33333/test

PRIMARY>db.getMongo().setSlaveOk();

PRIMARY>

Testing in the slave library

SECONDARY> db.user.find()

{ “_id” : ObjectId(“4eb68b1540643e10a0000000”), “id” : 1, “name” : “zhangsan” }

{ “_id” : ObjectId(“4eb68b1540643e10a0000001”), “id” : 2, “name” : “;lisi” }

there is another method to solve this error:
http://stackoverflow.com/questions/8990158/mongdodb-replicates-and-error-err-not-master-and-slaveok-false-code