The not master and slaveOk=false issue:
This error is displayed when you've connected to a standalone host:
Server returned not master error. Message: not master and slaveOk=false Code: 13435
And your MongoDB connection looks like this:
Reason:
This error means you are trying to read from a secondary replica set member. But the secondary member (the Slave) is not setup to perform reads.
How to fix:
There are three ways how to solve this issue. But we recommend the first way.
1. Use Replica Set connection mode
Edit your connection, specify 'Replica Set' in 'Connect to' field and add your host as single replica set member. Also you can add other replica set members to this connection.
2. Connect to a primary replica set memeber.
You need to discover the primary replica set member. You can ask your database administrator, hosting or cloud provider, find it with NoSQL Manager for MongoDB or with rs.status() command.
rs.status()
In this sample the primary node is mongodb1:27341.
Now update your connection:
Please note: primary node can be changed during replica set election process, in this case the error can occur again.
3. Use rs.slaveOk()
Allow this node to accept reads by running rs.slaveOk() in a mongo shell (connected to the node), but it isn't recommended.