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!
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
would correctly resolve into a single query to the second chunk. But this one (notice the 90 instead of 91 in the second clause)
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.