I have doubts on how shards are organized in Mongo D. Does primary also have a shard or its only across secondaries ? Also can someone elucidate the strongly consistent and eventually consistent architecture. If you know of any site that explains all these , kindly provide. Thanks
1 Answers
The site that explains how all of this works is the MongoDB manual. There's even a section specifically dedicated to sharding. If you want to look into consistency of data, look at replication, particularly at how data is propagated to secondary nodes.
In general, you should never connect directly to a shard, only to a router. The router will direct you to the shard(s) you need to perform the query. Shards themselves are basically just replica set nodes that contain a subset of the data, with each shard itself being a replica set containing a primary and any number of secondary nodes.
As for eventual vs. strong consistency, this is a subject with a number of considerations. For example, writes to secondaries are "eventually consistent", meaning that a write to the primary followed by a read to the secondary may lead to an inconsistency due to the write not having propagated to the secondary yet. Multi-document updates are also non-atomic (only atomic at the single document level), meaning that you can perform a read following a multi-document update such that only some of the documents reflect the update while others do not.
All of this is explained within the manual. Please be sure to read through the sections provided, including the subsections listed beneath them. You will find a lot of helpful information in there.

- 7,170
- 1
- 18
- 36
-
A replica set provides strict consistency for all read operations from the primary. What does this mean ? – RowLand Dec 18 '18 at 20:17
-
This means that the primary node will have the data immediately available upon being inserted or updated. A secondary node, however, is "eventually" consistent, meaning that the inserted/updated data is only available after a delay. – B. Fleming Dec 18 '18 at 23:14