snippetMinor
how to make secondary slave as readable in MongoDB?
Viewed 0 times
readableslavemakemongodbsecondaryhow
Problem
How do I make a secondary slave as readable in MongoDB?
We can do this via shell command
But how we can do it permanently for all session via config file?
We can do this via shell command
rs.slaveOk()But how we can do it permanently for all session via config file?
Solution
For
If you want secondary reads to be allowed by default for all shell sessions you can either:
-
add the
-
add to the global
mongo shell sessions there is a concept of mongorc files which include JavaScript to execute when the mongo 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:$ echo "rs.slaveOk()" >> ~/.mongorc.js-
add to the global
/etc/mongorc.js which is executed before the user-specific '~/.mongorc.js` (Note: requires MongoDB 2.6+):$ echo "rs.slaveOk()" | sudo tee -a /etc/mongorc.jsCode Snippets
$ echo "rs.slaveOk()" >> ~/.mongorc.js$ echo "rs.slaveOk()" | sudo tee -a /etc/mongorc.jsContext
StackExchange Database Administrators Q#105153, answer score: 4
Revisions (0)
No revisions yet.