Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
Will I have to attach shard key with my query to get performance?

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 ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

When your search is having the shard key index in the query , the mongodb sharded cluster routing service(mongos) will forward your query directly to the shard for which the query is addressed avoiding the "scatter-gather" request to all shards. This is because the mongos is caching the shard key index ranges and know in advance to which shard to address the request.

Moreover in specific write cases in mongodb version >=4.2 including the shard key in the query part is compulsory.

Also if your data is distributed between few shards sending broadcast requests is not an issue , but in case you have 100x shards you will need to wait for all 100 shards to search and reply to the mongos , so in general not using the shard key is a not scalable operation and need to be avoided whenever possible.

I hope this answer your question ...

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!