If two or more shards are added and then the first shard is removed, future addshard commands will fail with a duplicate key error.
> use admin
switched to db admin
> db.runCommand(
)
{ "shards" : [ ], "ok" : 1 }> db.runCommand(
{addshard : "server1:27018"})
{ "added" : "server1:27018", "ok" : 1 }> db.runCommand(
{addshard : "server2:27018"})
{ "added" : "server2:27018", "ok" : 1 }> db.runCommand(
{listshards : 1} )
{
"shards" : [
,
{ "_id" : "shard1", "host" : "server2:27018" } ],
"ok" : 1
}
> db.runCommand(
)
{
"msg" : "draining started successfully",
"state" : "started",
"shard" : "server1:27018",
"ok" : 1
}
> db.runCommand(
)
{
"msg" : "removeshard completed successfully",
"state" : "completed",
"shard" : "server1:27018",
"ok" : 1
}
> db.runCommand(
)
{
"shards" : [
],
"ok" : 1
}
> db.runCommand(
)
{
"ok" : 0,
"errmsg" : "E11000 duplicate key error index: config.shards.$id dup key: { : \"shard1\" }"
}