Mongo docs state that shard keys must be indexed, but this page on indexing doesn't mention them.
Is it safe to assume that shard keys are/behave as indexed fields?
Is there any benefit or drawback to indexing shard keys?
I think this page is an appropriate place for info on the relation of shards and indexes.
If this is mentioned on some sharding page a link in the relevant docs section would suffice.
Thanks
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Hi @kitsu, great question! In Azure Cosmos DB's API for MongoDB, sharding and indexing are separate concepts. There's no requirement to index your shard key in Azure Cosmos DB's API for MongoDB. However, as with any other property in your document, if this property is a common filter in your queries, we strongly recommend indexing the shard key. For more information about the relationship between partitioning and indexing, this doc is helpful: https://docs.microsoft.com/azure/cosmos-db/how-to-query-container. I can add it to the "Next Steps" section of this doc
@kitsu I made a doc update in the above PR per Tim's comments. We will now close this issue.
Most helpful comment
Hi @kitsu, great question! In Azure Cosmos DB's API for MongoDB, sharding and indexing are separate concepts. There's no requirement to index your shard key in Azure Cosmos DB's API for MongoDB. However, as with any other property in your document, if this property is a common filter in your queries, we strongly recommend indexing the shard key. For more information about the relationship between partitioning and indexing, this doc is helpful: https://docs.microsoft.com/azure/cosmos-db/how-to-query-container. I can add it to the "Next Steps" section of this doc