Hi,
I am using Ubuntu machine and i started three instance of mongod with replica set.
On primary instance i was able to see the db and collections and data.
But on secondary when i did query for find , i got this "error: { "$err" : "not master and slaveok=false", "code" : 13435 }".
so solution of this is , you have to run the rs.slaveOk() before quering to mongo shell know that you're allowing reads from a secondary.
Ex.
$ mongo hostAddress:ipAddress
>use databaseName;
> rs.slaveOk();
>db.collectionName.find();
Any doubt , Please share with me.
I am using Ubuntu machine and i started three instance of mongod with replica set.
On primary instance i was able to see the db and collections and data.
But on secondary when i did query for find , i got this "error: { "$err" : "not master and slaveok=false", "code" : 13435 }".
so solution of this is , you have to run the rs.slaveOk() before quering to mongo shell know that you're allowing reads from a secondary.
Ex.
$ mongo hostAddress:ipAddress
>use databaseName;
> rs.slaveOk();
>db.collectionName.find();
Any doubt , Please share with me.
Hi,
ReplyDeleteEvery Session we have to execute rs.slaveOk() to allowing reads from a secondary..
How to fix this without executing rs.slaveOk() to allow reads from a secondary.
Thanks,
Kishore E.
Hi Kishore,
ReplyDeleteWe can use below shorthand for this.
db.getMongo.setSlaveOk()
The current connection to allow read operations to run on secondary members.
Hi,
ReplyDeletekish:SECONDARY> db.getMongo.setSlaveOk()
2017-05-12T02:39:55.073-0400 E QUERY [thread1] TypeError: db.getMongo.setSlaveOk is not a function :
Please help me on this...
This below command is used when we create mongo connection using javascript and need to run query on slave
Deletedb.getMongo().setSlaveOk()
Ok, so you need to do this using console.
Check this file .mongorc.js in your home directory and add rs.slaveOk() there.
The file is being evaluated on each shell startup.
For detail check here.