Removing a Shard from a sharded cluster

Hi Everyone,

Here are some steps to remove a shard from a sharded cluster:

  • Connect to mongos
  • Authenticate using m103-admin
  • Run these commands:
   > use config
   > db.shards.find()
   { "_id" : "m103-repl", "host" : "m103-repl/192.168.103.100:27001,192.168.103.100:27003,m103.mongodb.university:27002", "state" : 1 }
   { "_id" : "m103-repl-2", "host" : "m103-repl-2/192.168.103.100:27004,192.168.103.100:27005,192.168.103.100:27006", "state" : 1 }

If you see your shards listed here, and you want to remove one shard suppose: m103-repl-2, then:

     > use admin
     > db.adminCommand( { removeShard: "m103-repl-2" } )

And I would encourage to look in the mongodb documentation for more information, here are some useful links:

Let me know if anyone has more doubts!

Kanika

3 Likes