I'm a new in MongoDB cluster. I have a question about config enable shading collection in MongoDB: I have a cluster :
Shard1: replical01/node1:27017, node2:27017
Shard2: replical02/node3:27017, node4:27017

2 config Server on other virtual machine.
Everything worked normally under manual. But I have a question as follows: how can I just shading a collection for only one shard. For example, I used mongos to create a database Test with 3 collection T1, T2, T3. Which T1 only located on shard1, T2 only on shard2. T3 is also located on the both shard1 and shard2. Please help me. Thank you and regards!!


1 Answer 1


You can enable sharding on collection base, i.e. collection T3 is sharded.

Unsharded collection are created in the Primary Shard, see Sharded and Non-Sharded Collections

Sharded and Non-Sharded Collections

A database can have a mixture of sharded and unsharded collections. Sharded collections are partitioned and distributed across the shards in the cluster. Unsharded collections are stored on a primary shard. Each database has its own primary shard.

Typically the Primary Shard is the least loaded shard at the time when the database was created. When you are not happy with the selected Primary Shard then you can move it with movePrimary command. But you have to move all collections of one database, you cannot move a single collection.

db.adminCommand( { movePrimary: <databaseName>, to: <newPrimaryShard> } )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.