dhythhsba
dhythhsba

Reputation: 1032

Mongodb sharded cluster $in VS $or

If I have MongoDB shurded cluster in sharded key: "my_key". I have to find in collection pack documents (about 10-500 items) with different my_key's. Foe example:

db.test.find({my_key: {$in:[1,3,5,67,45,56...]}})

Mongos knows where chunks with 'my_key' stored. Can mongos split my query to small queries to exact shards where documents stored? Or mongos will send this query to ALL shards?

And the same question about $or

db.test.find({$or:[{my_key: 1},{my_key: 3},{my_key: 5}...]})

Upvotes: 2

Views: 174

Answers (1)

dhythhsba
dhythhsba

Reputation: 1032

I have run tests.

If $in contains values only from one shard mongos will send SINGLE_SHARD query.

If $in contains values from several shards then mongos will send SHARD_MERGE query only for shards than contains needed data (not all cluster).

Upvotes: 3

Related Questions