Yandex Cloud
Search
Contact UsTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Yandex StoreDoc
  • Getting started
    • All tutorials
    • Sharding collections
    • Migrating data to Yandex StoreDoc
    • Migrating Yandex StoreDoc cluster from version 4.4 to 6.0
    • Migrating collections from a third-party Yandex StoreDoc cluster
    • Yandex StoreDoc performance analysis and tuning
    • Delivering data from Yandex Managed Service for Apache Kafka® using Yandex Data Transfer
  • Access management
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Public materials
  • Release notes

In this article:

  • Required paid resources
  • How to enable collection sharding
  • Heterogeneous sharding
  • Sharding example
  1. Tutorials
  2. Sharding collections

Sharding Yandex StoreDoc collections

Written by
Yandex Cloud
Updated at April 13, 2026
  • Required paid resources
  • How to enable collection sharding
    • Heterogeneous sharding
  • Sharding example

When sharding a Yandex StoreDoc cluster, the system automatically creates auxiliary hosts that are billed separately from your main database hosts:

  • The hosts created are either MONGOS and MONGOCFG
  • or MONGOINFRA

Alert

You can't unshard a cluster: to return a cluster to the state before it was sharded, you have to recreate it from a backup copy.

Consider sharding collections when distributing data across shards can significantly improve database performance or data availability. To increase availability, we recommend composing each shard of 3 or more database hosts.

Both usability and performance improvements depend on your choice of the shard key. Make sure that data is logically distributed across shards and that data in different shards is not interrelated.

You should use sharding for:

  • Large datasets: Collections exceeding 200 GB.
  • Collections with mixed contents, e.g., frequently and infrequently accessed data.
  • Collections requiring high read/write throughput: Sharding spreads the load across hosts to work around technical limitations.

To learn more about sharding, see Sharding in Yandex StoreDoc.

Required paid resourcesRequired paid resources

You pay for using a Yandex StoreDoc cluster: Computing resources allocated to hosts, including secondary service hosts, as well as storage and backup size (see Yandex StoreDoc pricing).

How to enable collection shardingHow to enable collection sharding

Warning

To configure sharding via the mongosh CLI, you must run all operations as a user with the mdbShardingManager role in the admin database.

  1. Enable sharding for the cluster.

  2. Connect to your MONGOS or MONGOINFRA host via the mongosh CLI and enable sharding:

    sh.enableSharding("<DB_name>")
    

    You can get the host type from the list of cluster hosts.

  3. Create an index for the sharded collection:

    db.getSiblingDB("<DB_name>").<collection_name>.createIndex( { "<index>": <index_type> } )
    
  4. Enable collection sharding:

    sh.shardCollection( "<DB_name>.<collection>", { "<index>": <index_type> } )
    
  5. Reconfigure applications accessing your database to use only MONGOS or MONGOINFRA hosts.

Heterogeneous shardingHeterogeneous sharding

If a collection includes documents with heterogeneous data types, we recommend creating shards based on the _id key values of the same type, using the Type Bracketing mechanism. This makes sharding and document search faster than when using _id values of different types.

Sharding exampleSharding example

Suppose you have a sharded Yandex StoreDoc cluster with a billing database. You need to enable sharding for the payment and addresses collections. In our example, the shard key consists of the payment index hash and the addresses value.

Procedure:

  1. Connect to the billing database. Make sure that the account you use to connect to the database has the mdbShardingManager role in the admin database.

  2. Enable sharding for the billing database:

    sh.enableSharding("billing")
    
  3. Create an index for the sharded collection:

    db.payments.ensureIndex( { "_id": "hashed" } )
    
  4. Create the required number of shards in the management console.

  5. Shard the collection based on its namespace:

    sh.shardCollection( "billing.payments", { "_id": "hashed" } )
    

Once this operation is complete, sharding will be enabled and configured. To confirm this, try listing all available shards using the sh.status() command.

Was the article helpful?

Previous
All tutorials
Next
Migrating data to Yandex StoreDoc
© 2026 Direct Cursus Technology L.L.C.