I am new to mongodb sharding. We know that we shard a database for scaling purpose. Where we need to use a sharding key so that the database distributing system can distribute data based on those key values. My question is - will I have to attach the sharding key with the query to avoid unnecessary query on other sharded db servers or does this work for mongodb sharding ?
Please read https://docs.mongodb.com/manual/sharding/.
In short if your query does not include the shard key, the query is performed on all replica sets and then mongos assemble the final results.