If you access MONGO through the shell, you want to query in secondary. The following error will appear:
[Email protected] ~]# Mongomongodb shell version:3.0.9connecting to:testabc:secondary> show dbs2016-02-20t02 : 13:18.527+0800 E QUERY error:listdatabases failed:{"note": "From ExecCommand", "OK": 0, "errmsg": "Not Master"}
There are two ways to implement a query from a machine:
The first method: Db.getmongo (). Setslaveok ();
The second method: Rs.slaveok ();
But this way has a disadvantage is that the next time through MONGO into the instance, the query will still error, for this can be done by the following ways
In order to avoid setting weights, there are a number of MongoDB under the VI mongorc.js, adding one line of content: Rs.slaveok (); , it is possible to avoid the original is primary, to avoid primary failure after another secondary switch to primary, the original primary repair into secondary time to execute Rs.slaveok () when no permissions. It's best to give the. Mongorc.js this file with the Add X permission:
VI monogorc.jsrs.slaveOk (): Wq
[[Email protected] ~] #chmod u+x. mongorc.js
That way, every time you go through the MONGO command, you can query.
[[email protected]ndary1 ~]# mongomongodb shell version: 3.0.9connecting to: testabc:PRIMARY> use mydbswitched to DB MYDBABC:PRIMARY> SHOW TABLESSYSTEM.INDEXESTESTC
the above method can resolve secondary again logon no longer prompts "not master ".
This article is from the "Steven Never give Up" blog, please be sure to keep this source http://wsw26.blog.51cto.com/1442148/1744267
MongoDB cannot get primary information solution directly in secondary