Cyral
Get Started Sign In

Finding the replica set name of a MongoDB cluster

When you protect a MongoDB cluster with Cyral, you must specify the cluster's replica set name. To get this name, there are three options.

Method 1. Extract it from the MongoShell connection URI

  1. On the cluster main page, click on the connect button:
  2. Select the Connect with the MongoDB Shell option
  3. Select MongoDB Shell version 3.4 or earlier

The replicaSet name should be listed as part of the connection string:

replicaSet=MyCluster-shard-0

Method 2. Connect to the cluster and extract the information

Access the MongoDB cluster (not authentication required) and issue the following commands:

use admin

db.isMaster() 

The db.isMaster() command should return the details about the cluster topology, which includes the replica set name:

{

    "topologyVersion" : {

        "counter" : NumberLong(7),

        "processId" : ObjectId("60f998149a67f8675309a2b4")

    },

    "hosts" : [

        "sample-yfxv9i-lb-1cdba32109a62ca6.elb.us-east-2.amazonaws.com:27020",

        "sample-yfxv9i-lb-1cdba32109a62ca6.elb.us-east-2.amazonaws.com:27019",

        "sample-yfxv9i-lb-1cdba32109a62ca6.elb.us-east-2.amazonaws.com:27021"

    ],

    "setName" : "MyCluster-shard-0",

    "ismaster" : true,

    "me" : "sample-yfxv9i-lb-1cdba32109a62ca6.elb.us-east-2.amazonaws.com:27019",

    "setVersion" : NumberLong(6),

    "primary" : "sample-yfxv9i-lb-1cdba32109a62ca6.elb.us-east-2.amazonaws.com:27019",

}



The name is associated with the key setName:

"setName" : "MyCluster-shard-0", 

 

Method 3. Get the Set Name by resolving the SRV cluster endpoint

If you have access to the cluster SRV (mongodb+srv) endpoint, you can resolve it to get the Replica Set name. For example, for the cluster endpoint: mongodb+srv://MyCluster.kloo5.mongodb.net, we can resolve it using the CLI tool nslookup:

$ ▶ nslookup -type=TXT mycluster.kloo5.mongodb.net
Server:        127.0.0.53
Address:    127.0.0.53#53

Non-authoritative answer:
mycluster.kloo5.mongodb.net    text = "authSource=admin&replicaSet=MyCluster-shard-0"


The above output contains the Replica Set name as part of the text response:

replicaSet=MyCluster-shard-0

 

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.