rs.slaveOk()
enables read operation on the slave member in a MongoDB replica set.
What function is used to disable it?
rs.slaveOk()
enables read operation on the slave member in a MongoDB replica set.
What function is used to disable it?
Simply type rs.slaveOk(false)
.
In the shell you can see what is the code that is executed for each command, so if you tipe rs.slaveOk
(without parenthesis) what you get is the following:
rs.slaveOk
function (value) {
return db.getMongo().setSlaveOk(value);
}
So slaveOk
is actually a function that accepts the boolean parameter and recalls setSlaveOk
, which is composed by the following code:
db.getMongo().setSlaveOk
function (value) {
if (value == undefined)
value = true;
this.slaveOk = value;
}
As you see, setSlaveOk
has true
as default value, so by specifying false you can prevent reading from the secondary.
EDIT: as correclty stated by dAm2K in the comment below, rs.slaveOk
has been deprecated from version 4.4 of MongoDB; just use rs.secondaryOk
.