Mongodb: Determining shard key strategy on compound index
1
vote
1
answer
1997
views
I have a collection with
170 millions+
documents and it is only going
to increase. The size of the collection is not that huge, currently
around 70 GB
.
The collection has two fields **indexed on: {AgentId:1, PropertyId:1}**.
Generally one imports a huge file(millions of documents) belonging to
a particular **AgentId but the PropertyId(non numeric nullable) is
mostly random unique value.**
Currently I have **two shards with shard key based on {_id: hashed}**. But
I am planning to **change the shard key to compound Index {AgentId:1,
PropertyId:1}** because I think it will improve query performance( most
of the queries are based on AgentId filter). Not sure whether one can
have a nullable
field in the shard key
. If this is the case then app
will make sure that the PropertyId is random no
.
**So looking to get a picture as to**
1. How the data will be distributed to shards during insertion
and how the range of a chunks are calculated during insertion?
2. Since the PropertyId is random value
. Does the compound key
fits the
definition of monotonically increasing value?
I am a newbie to MongoDB. And wanted to know if I am on the right path?
Asked by Sameer
(123 rep)
Dec 26, 2017, 05:41 PM
Last activity: Jul 8, 2025, 11:08 PM
Last activity: Jul 8, 2025, 11:08 PM