Config enable sharding collection in MongoDB cluster

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

Database Administrators Asked by muon.ha on December 26, 2020

1 Answers

One Answer

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

Answered by Wernfried Domscheit on December 26, 2020

Add your own answers!

Related Questions

HAPROXY for Postgres Failover Master/Replica

0  Asked on December 31, 2020 by jayson-gonzaga


Error 0xc000007b with Oracle 19c

2  Asked on December 28, 2020 by ben-a


Join to tables dynamically depending on data

2  Asked on December 28, 2020 by yellephen


PostgreSQL exits the shell when importing large data

2  Asked on December 26, 2020 by 3bdalla


Spike and time out errors every x th minute

1  Asked on December 25, 2020 by beginnerdba


Oracle RAC and DataGuard configuration

1  Asked on December 25, 2020 by yifan


Segragating First LSN and Last LSN from Output MySQL

0  Asked on December 24, 2020 by jabir-baig


Lossless Join Decomposition Criteria

1  Asked on December 23, 2020 by kevin-wu


Mongodb Upgrade from 1.8.2 to 4.4

0  Asked on December 23, 2020 by amanullah


SQLite database becomes corrupt

1  Asked on December 22, 2020 by jkozma


How do I export a multi table database with exceptions?

2  Asked on December 21, 2020 by soberuprising


MS SQL login periodically doesn’t work

2  Asked on December 20, 2020 by alonzo-hess


PostgreSQL: Find row with JSON object attribute in array

1  Asked on December 20, 2020 by karlsc


Hotel booking schema

1  Asked on December 20, 2020 by rakoun


Ask a Question

Get help from others!

© 2022 All rights reserved.