How do I make a secondary slave as readable in MongoDB?
We can do this via shell command
rs.slaveOk()
But how we can do it permanently for all session via config file?
mongodbnosql
How do I make a secondary slave as readable in MongoDB?
We can do this via shell command
rs.slaveOk()
But how we can do it permanently for all session via config file?
Best Answer
For
mongo
shell sessions there is a concept ofmongorc
files which include JavaScript to execute when themongo
shell starts. You can use this feature to extend or customise the behaviour of the interactive shell.If you want secondary reads to be allowed by default for all shell sessions you can either:
add the
rs.slaveOk()
command to the.mongorc.js
in the current user's home directory:add to the global
/etc/mongorc.js
which is executed before the user-specific '~/.mongorc.js` (Note: requires MongoDB 2.6+):