Sharding
Sharding is all about horizontal scaling which means adding more servers.
Single server or machine will not be able to handle read and write requests after a limit even if you increase GPU, CPU and memory etc.
In sharding, we have multiple computers which runs mongo server together.
Many computers or systems are there but only one mongo server.
They all will work together and data is distributed across those systems or computers or shards.
Queries run across all shards but that query will be processed by that shard which can process it.
How sharding works?
In the above diagram, mongo (router) functions using the shard key which is a field added to every document that is needed by the server to understand where the document belongs to.
Shard key configuration is not simple because shard key must be evenly distributed. It must be chosen wisely.
Query working with sharding
If find method contains shard key information then option 2 will be followed which is efficient one because it directly send the query to its unique shard.
But if you didn’t specify the shard key information then it will be distributed to all and responses will be given back.
So as a developer if you are using then you and your admin should choose shard key wisely on application needs.