Migrating Hash Sharded Collection in MongoDB to Cosmos DB API for MongoDB

Vaikakkara, Anoop 46 Reputation points
2023-08-16T15:40:49.82+00:00

I have to Migrate a sharded MongoDB cluster to Cosmos DB API for MongoDB. Now the source collection is hash sharded and supporting hash index on a particular field.

I read from Microsoft documents that

"Azure Cosmos DB uses hash-based partitioning to spread logical partitions across physical partitions. Azure Cosmos DB hashes the partition key value of an item. The hashed result determines the physical partition. Then, Azure Cosmos DB allocates the key space of partition key hashes evenly across the physical partitions."

I am really confused now that it states Cosmos DB uses hash-based partitioning but doesn't support a hash index on same field.

So when migrating from MongoDB, Can I provide the same as shard key and just ignore creating an index? Would that serve the purpose. Any suggestions on this will be helpful.

Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,845 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Vahid Ghafarpour 23,125 Reputation points
    2023-08-16T17:25:45.76+00:00

    In MongoDB, sharding involves distributing data across different shards based on the sharding key. This sharding key can be indexed using a hash index for efficient data distribution.

    But, Azure Cosmos DB uses hash-based partitioning to distribute data across physical partitions.

    The partition key in Cosmos DB serves a similar purpose as the sharding key in MongoDB, but there are some differences.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.