indexing - MongoDB: Combining compound shard key with different compound indexes -


let's have collection shard key of {a:1, b:1}.

alongside index shard key, have index of {a:1, c:1, d:1} - note shard key doesn't prefix index.

if run query specifying values fields a, c, , d, can mongo run combination of both indexes query correct shard , query data using second index? or not possible (perhaps because providing 'a' not sufficient choose correct shard)?

as stated in manual shard key indexes, index can index on shard key or compound index shard key prefix of index.

that means have have index of {a:1, b:1} or compound thereof, before using shard key.

now let's have 2 indexes of {a:1, c:1, d:1} , {a:1, b:1}. can run .explain() on query find out index utilised query. see explain results.

lastly, because query can not utilise shard key not mean not possible executed. means mongos need query shards, sub-optimal. when use shard key in query, able 'jump' directly correct chunk on correct shard.

you may find sharded cluster query router useful read.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -