u936293
u936293

Reputation: 16234

How to find the replica set name?

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?

Upvotes: 14

Views: 30677

Answers (5)

vikas pachisia
vikas pachisia

Reputation: 615

On connecting to primary mongod server locally you will notice that the prompt has the replica set name. Example:

ssh -i "keyfile.pem" MongoDPrimary:27017 (Connect to MongoD server) mongo (Connect to MongoD database)

s0:PRIMARY> (Mongo Shell Prompt)

In the above prompt: "s0" refers to the replica set name "Primary" refers to the primary replica.

rs.status() although good requires you to authenticate against the DB which can

Upvotes: 0

AB1
AB1

Reputation: 171

In the mongo shell - I executed rs.status() and copied the set name. In the Compass client, I selected the previously used / 'Recent' connection string from the left hand side and clicked the 'Fill in connection fields individually" link above the string box. Clicked the 'More Options' tab and pasted the set name into 'the Replica set name' field (mine was previously empty) This fixed it for me and was able to connect.

Upvotes: 1

W13 Official
W13 Official

Reputation: 99

Actually you can easily type the following on the Mongo Shell

rs.status().set

This will return you the replica set name

Upvotes: 8

Amine
Amine

Reputation: 368

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",
    ...
}

Upvotes: 23

Wan B.
Wan B.

Reputation: 18835

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.

Upvotes: 3

Related Questions