mongo在从库上默认不可读,需要设置才行,但是2.6和3.0的设置方法并不一样
mongodb 2.6一般报错如下
udb-02qe1w:SECONDARY> show tables
2016-05-23T19:29:27.526+0800 error: { "$err" : "not master and slaveOk=false", "code" : 13435 } at src/mongo/shell/query.js:131
处理方法:
udb-02qe1w:SECONDARY> db.setSlaveOk()
udb-02qe1w:SECONDARY> show tables
ddd
system.indexes
mongodb 3.0一般报错如下
Error: listDatabases failed:{ "note" : "from execCommand", "ok" : 0, "errmsg" : "not master" }
处理方法1
udb-cadhnj:SECONDARY> rs.slaveOk()
udb-cadhnj:SECONDARY> show dbs
admin 0.000GB
local 0.003GB
wozhua 0.114GB
wozhua_analysis 0.001GB
wozhua_app 0.001GB
wozhua_data 1.962GB
wozhua_deal 0.000GB
wozhua_o2o 0.076GB
处理方法2
udb-cadhnj:SECONDARY> db.getMongo().setSlaveOk()
udb-cadhnj:SECONDARY> show dbs
admin 0.000GB
local 0.003GB
wozhua 0.114GB
wozhua_analysis 0.001GB
wozhua_app 0.001GB
wozhua_data 1.962GB
wozhua_deal 0.000GB
wozhua_o2o 0.076GB