0

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!!

2
  • "But I have a question as follows: how can I just shading a collection for only one shard." You cannot shard a collection to be on one shard. Only, unsharded collections are located on the primary shard. All sharded collections are distributed among shards.
    – prasad_
    Oct 13, 2020 at 9:48
  • @prasad_ : Thanks bro ! your information is very useful for me.
    – muon.ha
    Oct 14, 2020 at 7:55

1 Answer 1

0

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> } )
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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