Mehdi LAMRANI
Mehdi LAMRANI

Reputation: 11597

Connecting to mongos on an Atlas Cluster to see Sharding Status

I just need to perform an sh.status() command to see the sharding status of my mongodb database.
This command needs to be performed on a mongos, and it is not (yet) clear to me how to perform that. My guess is that I should simply launch a mongo shell from a mongos server directly, but Atlas does not seem to provide direct access to them (I may be wrong).

EDIT :

Here is the exception I get when I execute the command from a remote Mongo Shell connected to my cluster :

mongoc-shard-00-00-wddpo(mongos-3.6.0)[mongos] mydb> sh.status()
printStackTrace@src/mongo/shell/utils.js:73:15
DBCollection.prototype.aggregate@/Users/jondoe/.mongorc.js:98:13
sh.getRecentMigrations@/Users/jondoe/.mongorc.js:1388:28
printShardingStatus@/Users/jondoe/.mongorc.js:1497:30
sh.status@src/mongo/shell/utils_sh.js:89:5
@(shell):1:1

2017-12-12T16:31:59.985+0100 E QUERY    [thread1] uncaught exception:         aggregate failed: {
  "ok": 0,
  "errmsg": "The 'cursor' option is required, except for aggregate with the explain argument",
  "code": 9,
  "codeName": "FailedToParse",
  "$clusterTime": {
    "clusterTime": Timestamp(1513092719, 27),
    "signature": {
      "hash": BinData(0, "Ok0isqe1nHr+D/I9344pcNdxapA="),
      "keyId": NumberLong("6496824061736255491")
    }
  },
  "operationTime": Timestamp(1513092719, 27)
}

UPDATE

Since I was using Mongo Shell 3.4, I updated to 3.6 After some cleaning (I had to manually delete the home/.mongorc.js prior to installing 3.6 otherwise it had a mess) everything worked as expected

mongo "mongodb+srv://mongoc-wddpo.mongodb.net/mydb" --authenticationDatabase admin --username jondoe --password strongestpasswordever
MongoDB shell version v3.6.0
connecting to: mongodb+srv://mongoc-wddpo.mongodb.net/mydb
MongoDB server version: 3.6.0
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
mongos> sh.status()
--- Sharding Status --- 
  sharding version: {
    "_id" : 1,
    "minCompatibleVersion" : 5,
    "currentVersion" : 6,
    "clusterId" : ObjectId("5a2953b4841c53c7b10a53f5")
  }
  shards:
        {  "_id" : "Mongoc-shard-0",  "host" : "Mongoc-shard-0/mongoc-shard-00-00-wddpo.mongodb.net:27017,mongoc-shard-00-01-wddpo.mongodb.net:27017,mongoc-shard-00-02-wddpo.mongodb.net:27017",  "state" : 1 }
        {  "_id" : "Mongoc-shard-1",  "host" : "Mongoc-shard-1/mongoc-shard-01-00-wddpo.mongodb.net:27017,mongoc-shard-01-01-wddpo.mongodb.net:27017,mongoc-shard-01-02-wddpo.mongodb.net:27017",  "state" : 1 }
        {  "_id" : "Mongoc-shard-2",  "host" : "Mongoc-shard-2/mongoc-shard-02-00-wddpo.mongodb.net:27017,mongoc-shard-02-01-wddpo.mongodb.net:27017,mongoc-shard-02-02-wddpo.mongodb.net:27017",  "state" : 1 }
        {  "_id" : "Mongoc-shard-3",  "host" : "Mongoc-shard-3/mongoc-shard-03-00-wddpo.mongodb.net:27017,mongoc-shard-03-01-wddpo.mongodb.net:27017,mongoc-shard-03-02-wddpo.mongodb.net:27017",  "state" : 1 }
  active mongoses:
        "3.6.0" : 12
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours: 
                No recent migrations
  databases:
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }
                config.system.sessions
                        shard key: { "_id" : 1 }
                        unique: false
                        balancing: true
                        chunks:
                                Mongoc-shard-0  1
                        { "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : Mongoc-shard-0 Timestamp(1, 0) 
        {  "_id" : "mydb",  "primary" : "Mongoc-shard-1",  "partitioned" : false }

Upvotes: 0

Views: 1768

Answers (1)

Alex Blex
Alex Blex

Reputation: 37048

When you deploy a sharded cluster, you connect to mongos and can execute sh.status().

In the cluster overview click "Connect", choose "Connect with the Mongo Shell", and use connection string provided.

Update

Just tested it with stock ubuntu client upgraded to v3.6 and new v3.6 cluster.

The client:

$ mongo --version
MongoDB shell version v3.6.0
git version: a57d8e71e6998a2d0afde7edc11bd23e5661c915
OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1604
    distarch: x86_64
    target_arch: x86_64

Connection string copy-pasted from Atlas UI:

$ mongo "mongodb+srv://cluster14-74xqx.mongodb.net/test" --authenticationDatabase admin --username user --password password

The shell:

MongoDB shell version v3.6.0
connecting to: mongodb+srv://cluster14-74xqx.mongodb.net/test
MongoDB server version: 3.6.0
mongos> sh.status()
--- Sharding Status ---
  sharding version: {
    "_id" : 1,
    "minCompatibleVersion" : 5,
    "currentVersion" : 6,
    "clusterId" : ObjectId("5a3106712d26976bf628d75b")
  }
  shards:
        {  "_id" : "Cluster14-shard-0",  "host" : "Cluster14-shard-0/cluster14-shard-00-00-74xqx.mongodb.net:27017,cluster14-shard-00-01-74xqx.mongodb.net:27017,cluster14-shard-00-02-74xqx.mongodb.net:27017",  "state" : 1 }
        {  "_id" : "Cluster14-shard-1",  "host" : "Cluster14-shard-1/cluster14-shard-01-00-74xqx.mongodb.net:27017,cluster14-shard-01-01-74xqx.mongodb.net:27017,cluster14-shard-01-02-74xqx.mongodb.net:27017",  "state" : 1 }
  active mongoses:
        "3.6.0" : 6
  autosplit:
        Currently enabled: yes
  balancer:
        Currently enabled:  yes
        Currently running:  no
        Failed balancer rounds in last 5 attempts:  0
        Migration Results for the last 24 hours:
                No recent migrations
  databases:
        {  "_id" : "config",  "primary" : "config",  "partitioned" : true }

Upvotes: 1

Related Questions