MongoDb’s “not master and slaveok = false” error and its solution

Time:2019-3-23

When using mongodb, there is a “not master and slaveok = false” error because secondary does not allow reading and writing.

Because mongodb is the master and backup in the system, switching between the master and backup may also lead to this problem.

Replace the IP in the command Mongo — username = root — password = 123456 — host = 192.168.0.100 admin with the main IP and the query is normal.

Question note:

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 slaveOk at connection time or in the main library, Secondary shares the pressure of reading, and Primary only undertakes write operations.

For the second node in replica set, it is unreadable by default.

MongoDb's

Set slaveok = OK on the main library

MongoDb's

summary

Above is the whole content of this article. I hope that the content of this article has a certain reference learning value for everyone’s study or work. Thank you for your support for developpaer. If you want to know more about it, please check the links below.