Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6868063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:23:16+00:00 2026-05-27T03:23:16+00:00

Suppose collection coll has an index {ts : 1, X : 1 , Y

  • 0

Suppose collection “coll” has an index

{ts : 1, X : 1 , Y : 1}

Whre ts, X and Y are type NumberLong.

The collection is configured for sharding on ts,X

Could you help me understand how the following queries will execute?

1) Unbounded range: will the following query be targetted at those shards hosting ranges ts > 100000000 only or is this a global query?

db.coll.find({ts : {$gt : 100000000}}) 

2) Bounded range: if so, how about this one – will this be targeted or global? Is mongos clever enough to parse out the query?

db.coll.find({$and : [{ts : {$gt : 100000000}}, {ts : {$lte : 110000000}}]})

3) Finally — what happens w/ multiple bounded ranges:

db.coll.find({$or : [[{$and : [{ts : {$gt : 100000000}}, {ts : {$lte : 110000000}}]}, {$and : [{ts : {$gt : 500000000}}, {ts : {$lte : 510000000}}]}]]})

I am unable to find any reference to range queries on http://www.mongodb.org/display/DOCS/Sharding+Introduction…!

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:23:17+00:00Added an answer on May 27, 2026 at 3:23 am
    1. Will hit only those shards that contain documents that can possibly comply to your range criteria. Mongos is able to determine this because your querying on the shard key and thus knows which are eligible. Queries to invidual shards are executed in parallel.
    2. Same as 1). Mongos is intelligent enough to know which chunks to hit for this.
    3. Each clause in the $or will be evaluated seperately. If clauses resolve to the exact same query plan and chunk range they will/should be combined. You can check this by running an explain() on your query in the sharded environment and keep an eye on the returned information. If it contains a “clauses” object it means not all clauses in your $or can use the same query execution plan.

    That’s the theory but mongos query plans tend to be a little inconsistent. For example with a “ts” shard key and one chunk at each of two shards holding range minkey-50 and the other 51-maxkey respectively, this query

    {$or:[{$and:[{ts:{$gt:90}}, {ts:{$lt:100}}]}, {$and:[{ts:{$gt:91}}, {ts:{$lt:100}}]}]}
    

    would correctly resolve into a single query to the second chunk. But this one (notice the 90 instead of 91 in the second clause)

    {$or:[{$and:[{ts:{$gt:90}}, {ts:{$lt:100}}]}, {$and:[{ts:{$gt:90}}, {ts:{$lt:100}}]}]}
    

    would actually result in a query to both shards which makes very little sense since you’re basically asking it to $or two clauses that are exactly the same. Basically, try to use explain() and other monitoring tools to see how your queries behave in a sharding environment to be sure it works as intended.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I create collection like Collection<IMyType> coll; Then I have many implelentations of IMyTypem
Suppose I have the following HTML: <form id=myform> <input type='checkbox' name='foo[]'/> Check 1<br/> <input
Suppose each Person has a collection of favorite Books. So I have a table
Suppose you have Role class, and each Role has a collection of Users. I
Suppose I create a document in a MongoDB collection with the following structure and
Suppose you've a reference of type java.util.Collection in a method and cannot say what
I need to select distinct highways from a roads collection. I suppose I could
Suppose I have a collection defined as: IEnumerable<Employee> Employees; Entity Employee has property Person.
Suppose I have the following method, which can be used to create a collection
Suppose I have the following classes: class X; class Y; class Collection { public:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.