Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the replica set name?

Tags:

mongodb

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?

like image 748
Old Geezer Avatar asked Jun 28 '18 16:06

Old Geezer


3 Answers

To find the replica set name:

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",
    ...
}
like image 98
Amine Avatar answered Nov 08 '22 13:11

Amine


Actually you can easily type the following on the Mongo Shell

rs.status().set

This will return you the replica set name

like image 43
W13 Official Avatar answered Nov 08 '22 13:11

W13 Official


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.

like image 32
Wan Bachtiar Avatar answered Nov 08 '22 13:11

Wan Bachtiar