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
Similar Posts:
- mongodb:E QUERY [thread1] SyntaxError: missing ; before statement @(shell):1:4
- [Solved] Mongodb Error: NETWORK [thread1] Failed to connect to 127.0.0.1:27017
- Detection field exists in mongodb
- No package mongodb-org available. [How to Solve]
- Mongodb access control is not enabled for the database
- [Solved] Mongodb startup error: about to fork child process, waiting until server is ready for connections.
- Mongodb Cannot Start: child process failed, exited with error number 100
- MongoDB Startup Error: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
- Raspberry pie: How to Solve Mongodb installation error
- Unable to start mongod after installing mongodb in Ubuntu