MongoDB 샤딩된 컬렉션 풀기?

아래와 같은 방법으로 하면…

database = 'rnr_sessions'
collection = database + '.sessions'
 
sh.stopBalancer()
primary = db.databases.findOne({_id: database}).primary
 
// move all chunks to primary
db.chunks.find({ns: collection, shard: {$ne: primary}}).forEach(function(chunk){
    print('moving chunk from', chunk.shard, 'to', primary, '::', tojson(chunk.min), '-->', tojson(chunk.max));
    sh.moveChunk(collection, chunk.min, primary);
});
 
// unshard
db.collections.remove({ "_id" : collection })
db.chunks.remove({ ns : collection })
 
// flush all mongos, is this neccessary?!
use admin
db.runCommand({ flushRouterConfig: 1 })

참고자료) [Command to unshard a collection]