【转】MongoDb的“not master and slaveok=false”错误及解决方法
[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 在主库上设置 slaveok=ok [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> 在从库进行测试 SECONDARY> db.user.find() { "_id" : ObjectId("4eb68b1540643e10a0000000"), "id" : 1, "name" : "zhangsan" }
{ "_id" : ObjectId("4eb68b1540643e10a0000001"), "id" : 2, "name" : ";lisi" }
另外可参考如下解决方案:
http://stackoverflow.com/questions/8990158/mongdodb-replicates-and-error-err-not-master-and-slaveok-false-code
转自 http://blog.163.com/lgh_2002/blog/static/44017526201301123736391/