Does multiple shard key help performance in mongodb?

Since the sharding database uses a shard key to separate chunks and route requests, so I think that maybe more shard key can help make more queries targets

I tried to specify several such keys

db.runCommand( { shardcollection : "test.users" , key : {_id:1, email : 1 ,address:1} 

but I have no idea if it works and what it does

+4
source share
2 answers

To be clear here, you can only have one shard key. Thus, you cannot have multiple shard keys.

However, you are proposing a composite index as a fragment key. This can be done, but there are some limitations.

For example, the combination of _id , email and address must be unique.

Documents for selecting a fragment key . There are a few more considerations that I cannot list here. See this document.

+3
source

Shard key selection based on:

 {coarseLocality : 1, search : 1} 

coarseLocality is any region that you want for your data, search is a general search for your data.

You should have a pointer to the key that you are plotting, so if you choose a random key that you don’t request, you basically lose the index. Each additional index makes records slower, so it is important to keep as many indexes as possible.

Thus, an increase in the combination of combinations of fragments does not help much.

Excerpt from Christina Chodrow's book, MongoDB Scaling.

+3
source

Source: https://habr.com/ru/post/1347898/


All Articles