简体   繁体   中英

What's the equivalent of `rs.slaveOk()` for config file in MongoDB?

I have set up my MongoDB on local machine with replicaSet , and I have this error:

An error occurred while loading navigation: 'not master and slaveOk=false': It is recommended to change your read preference in the connection dialog to Primary Preferred or Secondary Preferred or provide a replica set name for a full topology connection.

If I don't exec this command on secondary servers,

rs.slaveOk()

After using the command, the problem is solved, but only temporarily. After restarting the servers, the above error pops up again, I again have to stop it using the command.

How can I somehow define the slaveOk in a config file, so that I don't have to allow slaveOk each time I start the server?

Your connection string should look something like this:

mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myRepl

If you are connecting from shell

mongo "mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myRepl"

OR

mongo --host myRepl/mongodb0.example.com.local:27017,mongodb1.example.com.local:27017,mongodb2.example.com.local:27017

Where myRepl is the replica set name, mongodbX.example.com.local:27017 are your nodes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM