On mongodb Fragmentation

  mongodb, question

The company originally used Mongodb single node to store some document contents, but now it will deploy the form of slice copy. I have read some related articles on the internet and encountered such problems here. For example, create a database, then execute sh.enableSharing (database name), then sh.shardCollection a collection name, and then use mongorestore to restore a collection (that is, the business data of the previous day) to this database.
The chip key is set to _id in the form of hashed
Then sh.status ()
See图片描述

There is “yes” in autoSplit and “chunks” in all 3 slices. This should be that the database is already in slice mode, and then print the detailed information according to “Use verbose if you want to force print” below.
Why does it show up again
图片描述

Said that the database has not set up the fragment?
In addition, it was originally to create a new set in MONGODB in the form of time stamps every day, and then insert the corresponding data. However, I think the configuration of fragments is to set up the database first and then set up the collection. Can all collections be fragmented after the database is set?

In addition, I have read some articles and said that setting slice keys can affect the storage of documents in slices, such as sequential storage or random storage using hash. If a fixed percentage of memory chip keys are stored, how should chip keys be set? For example, slice one stores two-thirds of the data while slice two stores one-third of the data.

Then use verbose if you want to forceprint below to print the detailed information.

printShardingStatusPlease refer to the documentation for the usage of:db.printShardingStatus(). The article that you saw introducing this method may be wrong (or a very old version? ), there is no such usage as screenshots in recent versions.

Can all collections be fragmented after the database is set?

No. I don’t know the content of the collection, and I’m not sure the key of the slice. How can I set the slice automatically? But the command to slicesh.shardCollectionIt can be executed repeatedly, so it can be executed once more when uncertain, which will not cause harm.

In addition, I have read some articles and said that setting slice keys can affect the storage of documents in slices.

This topic may be a little too big to begin with. The official document explains the selection principle of shards in great detail. Please refer to the document:Shard Keys
Selecting slices according to these principles can make your data as evenly distributed as possible on different slices. The function you want is calledTag Aware Sharding, that is, data is distributed to different slices through Tag according to the scope of shard key. This function is also described in detail in the document. Please refer to the link above.