[英]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:我已经用 replicaSet 在本地机器上设置了我的MongoDB ,我有这个错误:
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.加载导航时出错:'not master and slaveOk=false':建议将连接对话框中的读取首选项更改为 Primary Preferred 或 Secondary Preferred,或为完整拓扑连接提供副本集名称。
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?如何以某种方式在配置文件中定义slaveOk
,这样我每次启动服务器时都不必允许slaveOk
?
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如果您从 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.其中myRepl
是副本集名称, mongodbX.example.com.local:27017
是您的节点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.