To move a chunk manually, we need to issue the following command after connecting to mongos and the admin database:
> db.runCommand( { moveChunk : 'mongo_books.books' ,
find : {id: 50},
to : 'shard1.packtdb.com' } )
Using the preceding command, we move the chunk containing the document with id: 50 (this has to be the shard key) from the books collection of the mongo_books database to the new shard named shard1.packtdb.com.
We can also more explicitly define the bounds of the chunk that we want to move. Now the syntax is as follows:
> db.runCommand( { moveChunk : 'mongo_books.books' ,
bounds :[ { id : <minValue> } ,
{ id : <maxValue> } ],
to : 'shard1.packtdb.com' } )
Here, minValue and maxValue are the values that we get from db.printShardingStatus().
In the example used previously, for chunk2, minValue would be -6 and maxValue would be 0.
Do not use find in hash-based sharding. Use bounds instead.