'not master and slaveOk=false' error connecting with Compass

Getting this error connecting with Compass!

An error occurred while loading navigation: ‘not master and slaveOk=false’: It is recommended to change your read preference in the connection dialog to Primary Preferred or Secondary Preferred or provide a replica set name for a full topology connection.

Screenshot_2019-10-09_20-47-27|636x500

Try turning on SRV. Click the SRV button in Compass to turn it on and then connect.

Hi @Milo_98897

It might be due to some network related issue.

Can you please make sure you are able to ping the cluster?

ping cluster0-shard-00-00-jxeqq.mongodb.net

And also please verify that port 27017 is not blocked by clicking http://portquiz.net:27017

On some occasions, even though the above mentioned tests passes, network is still a problem. So please make sure you are not connected to any vpn and firewall/antivirus is disabled. You can also try to connect from some other network such as your home network .

Hope it helps!

If the issue still persists please feel free to get back to us. Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer

I doubt this is a networking issue but I could be wrong.

Based on the error message:

  1. 27017 is a Secondary
  2. this Secondary node doesn’t accept reads (i.e. slaveOk is false). As a result, any Read Preference that attempts to read from a Secondary will fail.

Therefore, the only two options I can see is, use the port number belonging to the Primary, or if you don’t know what the other ports are, use SRV.

Another student on another thread reported that the Primary for this replica set (if I remember correctly) keeps changing.

SRV causes Compass to not see the Mongod instance.

Thanks for your reply. After trying again this morning (with absolutely no changes on my end, same saved ‘favorite’ connection) the problem seems to have resolved, and i can successfully connect.

I had of course already checked the ping, which showed all packets successful.

Thanks for your reply. After trying again this morning (with absolutely no changes on my end, same saved ‘favorite’ connection) the problem seems to have resolved, and i can successfully connect.

Thanks for your reply. After trying again this morning (with absolutely no changes on my end, same saved ‘favorite’ connection) the problem seems to have resolved, and i can successfully connect.

Ok. SRV isn’t setup in this Cluster.

Hi @007_jb,

In Compass, network related issues manifest in so many ways that it is hard to keep it out of the consideration when debugging any issue and it is always preferred to make sure that at least these two basics tests are passing before going any further.

27017 is the port number on which the clusters are running. All the nodes in the Cluster0-shard-0 replica set which we use in our M001 : MongoDB Basics course runs on the same port i.e. 27017.

You can easily verify this by connecting to the cluster from the mongo shell and then running the command rs.status()

Yes, this is correct that the secondaries will not serve the read requests if the slaveOk property for the current connection has been set to false but for this replica set it does not apply because this property has been set to true and read from secondaries are permissible.

In your connection string if you have included the name of the replica set along with any of its members host and port address, you should not worry about which node is the primary because it will always connect you to the primary.

In this screenshot, I can see that the replica set name has been provided so which node is the primary is not of any concern here.

Yes, the primary nodes keeps on changing from time to time due to some very obvious reasons. The thread that you are referring to here was for one of our student’s sandbox cluster.

You can totally connect to the atlas class cluster using the SRV Records as it has been already configured for the same. For doing that please use the connection string mentioned below and select the SRV Record option.

cluster0-jxeqq.mongodb.net

Hope it helps. BTW, I like your debugging style and your engagement with the community. Keep up the good work :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer

I didn’t take this course so I was none the wiser about the setup. I was expecting the setup to be similar to all other courses that use different ports per node. And I can now see that it’s running on the same port with different host names after login in yesterday for the first time.

Good to know for future debugging! :smiley::+1:

Good to know too! You guys don’t seem to recommend this option most times. Any particular reasons?

Thanks! Do what we can to help! :wink:

1 Like

Hi @007_jb,

When the videos were recorded, Compass did not have this functionality. At the moment, we do not recommend this because it may create unnecessary confusion among the learners.

Thanks,
Shubham Ranjan
Curriculum Support Engineer