I have an M0 instance created at mongodb.com using all the defaults. I copied the URI connection string from the Atlas Connection dialog. It was recognized in mongoDB Compass and the connection details form was automatically filled out.
It worked fine for a few weeks and I could browse my documents. Then all of a sudden I am getting:
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.
I searched and most suggest to explicitly specify the Replica Set Name
. The automatic settings have Read Preference
set to Primary and the Replica Set Name
is blank.
Why is this error occurring suddenly, and how do I find out the replica set name to use?
Open the mongo shell and type the command:
rs.status()
this will give you a document with the replica set name (under the key set
):
{
"set" : "Name of your replica set",
...
}
Actually you can easily type the following on the Mongo Shell
rs.status().set
This will return you the replica set name
Why is this error occurring suddenly
The error message is triggered because there was a Replica Set Election that changed the state of the instance that you're connecting from Primary to Secondary.
When connecting using MongoDB Compass, and no replica set name specified. The connection would be a direct connection to the instance, instead of a connection to the replica set (automatic topology discovery).
how do I find out the replica set name to use?
On MongoDB Atlas project page, select the Deployment
link on the left hand side menu. Under Processes
tab, with Topology
view you should see the replica set name (this should be the default view presented when you click on Deployment
).
Generally, the replica set name is the cluster name plus -shard-0
. i.e. cluster name test
, replica set name is test-shard-0
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With