1
votes

Is it possible to query the data directly from a specific Shard?

I mean when I run this command db.collection.getShardDistribution() on mongos I get the info that my data is split between shards, and I am wondering if it is possible to query the data directly by connecting to the shard.

1

1 Answers

2
votes

Your application can't communicate directly with one shard and it is useless too. Maybe the following picture can help you to understand how sharding works in MongoDB. enter image description here

The query router (also called mongos) works as a middleware: it receives a request from the client and directs it automatically to the correct(s) shard(s); when a shard is ready, sends its answer to this query router which shall forward it to the client. Using mongoDB sharding, the mongos instances use the metadata of your config servers to route a request just towards the affected shard(s). There is not any need to communicate directly with a shard, MongoDB does it for you.