MongoDB cannot get primary information solution directly in secondary

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.