I am trying to go through the documents for mongodb sharding and I am a bit confused about how the primary shards are assigned and the meaning of primary shards
As per the documentation it stats that
Every database has a primary shard that holds all the un-sharded collections for a database. The primary shard has no relation to the primary in a replica set.
does this mean that a primary shard is the shard (or the collection of servers) in the shard where the database was first created ?
Say I have 3 shards s0, s1 and s2. In each shard i have 3 servers
- s0 Server 1 (Primary)
- s0 Server 2 (Secondary)
s0 - Server 3 (Secondary)
s1 - Server 4 (Primary)
- s1 - Server 5(Secondary)
s1 - Server 6(Secondary)
s2 - Server 7(Primary)
- s2 - Server 8(Secondary)
- s2 - Server 9(Secondary)
Now when I create a new database via a mongoclient and via mongos . Now say that request goes to the shard 1 (s1). Since create database is a write operation it would go to the server 4 in shard 1 and thus s1 becomes by primary shard ?
If on the other hand the request would have traversed to s2 shard then server 7 would being primary would have created the collection and then s2 would have been my primary shard ?
Is this understanding correct or I am going wrong some where ?