Details
-
Improvement
-
Resolution: Duplicate
-
Major - P3
-
None
-
2.4.3
-
None
Description
I think these commands can be used to unshard a collection with moving all chunks to primary of database.
database = 'test'
|
collection = database + '.fs.chunks'
|
|
|
sh.stopBalancer()
|
use config
|
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" : "test.fs.chunks" })
|
db.chunks.remove({ ns : collection })
|
|
|
// flush all mongos, is this neccessary?!
|
use admin
|
db.runCommand({ flushRouterConfig: 1 })
|
Is this a correct code? Did I missed something or not?
Attachments
Issue Links
- duplicates
-
SERVER-4000 command to change shard key of a collection
-
- Closed
-
-
SERVER-1037 Sharding - command to remove or "unshard" a collection
-
- Closed
-
- is duplicated by
-
SERVER-13108 Error after UnSharding Collection - mongodb
-
- Closed
-
- is related to
-
SERVER-16264 Allow unsharding a collection when all chunks are on the primary shard
-
- Closed
-
- related to
-
SERVER-4246 allow resharding by more-specific shard key.
-
- Closed
-