Query impact in compound key for sharding

Hi All

If I choose a compound key as shard key, will mongo db be able to route it to appropriate shards if I pass only one key( first key in compound key) in the queries. All the AI tools are suggesting it will be able to route. But I am not able to find the documentation for the same in mongo page.

Thanks

Hey Guru,

It depends on the operation and the MongoDB version you’re using.

  • What MongoDB version are you on?
  • and what’s the compound key?
  • and which operations will you only be passing the first key to?

Thanks for your quick response

  • What MongoDB version are you on?

We will use the latest Mongo in MongoDB Atlas(8.0)

  • What’s the compound key?

Compound key for three fields in the Collection. The first key would be tenantID. It doesn’t include _id. Sometimes I would pass two fields. The max chunk size is recommended to be 128MB. If I keep my first key alone as shard key, then my chunk size would be more than 4GB in certain cases. Hence I thought adding multiple fields could reduce the chunk size. But most of the other operations would pass all the fields in the compound key.

  • which operations will you only be passing the first key to?

For operations like getAll, DeleteAll for a particular tenant.

Can anyone help here? I don’t have access to a sharded cluster yet