Mongodb – Is it possible to delegate responsibility for specific indexes for a collection to specific shards in a mongoDB database

indexmongodbnosqlscalabilitysharding

Is it possible to delegate responsibility for specific indexes for a collection to specific shards in a mongoDB database?

For instance, say I have a collection called 'books':

{ title: <string>, pages_in_book: <number>, price: <number>, author: <string> }

And say I want 3 indexes for this collection: one for the price, one for pages_in_book, and one for author.

Also say I have 3 shards.

Can I have each of these shards be responsible for updating one index each when a new document is inserted into the 'books' collection?

I want to do this because I plan to make a write-heavy application. User actions would initiate the creation of multiple documents at once and each document would need to be added to multiple indices like above (but five or six indices in my real case). I could distribute the writes using a shard key (with luck here, the documents' writes and it's writes to the collection's indices would be distributed evenly to the different shards but I could get unlucky if no good shard keys) or distribute the writes so that each shard is assigned an equal amount of indexes to be responsible for (extremely more likely for there to be a near even distribution of writes this way???)

Best Answer

As Antonios wrote, you cannot distribute different indexes to different shards. To distribute load, you should select good shard key and this case key what is used most (best situation is if all queries would always use "some" key) it should be "hashed". ( {"some":"hashed"} )

Check hased sharding from here!