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.
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.
Set slaveok = OK on the main library
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.