jstests/sharding/balancing_sessions_collection.js
/*
 * Removes the given shard from the cluster, waits util the state is completed, and
 * decrements numShards.
 */
Removes the given shard from the cluster, waits util the state is completed, and
decrements numShards.
Removes the given shard from the cluster waits util the state is completed and decrements numShards .
function removeShardFromCluster(shardName) {
    assert.commandWorked(st.s.adminCommand({removeShard: shardName}));
    assert.soon(function() {
        const res = st.s.adminCommand({removeShard: shardName});
        if (!res.ok && res.code === ErrorCodes.ShardNotFound) {
            return true;
        }
        assert.commandWorked(res);
        return ("completed" == res.state);
    }, "failed to remove shard " + shardName, kBalancerTimeoutMS);
    numShards--;
}
function removeShardFromCluster ( shardName ) { assert . commandWorked ( st . s . adminCommand ( { removeShard : shardName } ) ) ; assert . soon ( function ( ) { const res = st . s . adminCommand ( { removeShard : shardName } ) ; if ( ! res . ok && res . code === ErrorCodes . ShardNotFound ) { return true ; } assert . commandWorked ( res ) ; return ( "completed" == res . state ) ; } , "failed to remove shard " + shardName , kBalancerTimeoutMS ) ; numShards -- ; }
Removes the given shard from the cluster, waits util the state is completed, and
 decrements numShards.
Removes the given shard from the cluster waits util the state is completed and decrements numShards .
// If the config server primary steps down right after removing the config.shards doc // for the shard but before responding with "state": "completed", the mongos would retry // the _configsvrRemoveShard command against the new config server primary, which would // not find the removed shard in its ShardRegistry if it has done a ShardRegistry reload // after the config.shards doc for the shard was removed. This would cause the command // to fail with ShardNotFound.