-
Type: Improvement
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.4.3
-
Component/s: Sharding
-
None
I think these commands can be used to unshard a collection with moving all chunks to primary of database.
Unable to find source-code formatter for language: javacsript. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
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?
- 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