Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Managed Service for MongoDB
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Information about existing clusters
    • Creating clusters
    • Database migration to Yandex.Cloud
    • Connecting to databases
    • Stop and start the cluster
    • Changing cluster and database settings
    • MongoDB version upgrade
    • Database management
    • Managing hosts in a cluster
    • Managing database users
    • Managing backups
    • How to manage shards
    • Deleting clusters
  • Solutions
    • Sharding collections
  • Concepts
    • Relationship between service resources
    • Host classes
    • Network in Yandex Managed Service for MongoDB
    • Quotas and limits
    • Storage types
    • Backups
    • Replication
    • Sharding
    • Users and roles
    • Supported clients
  • Access management
  • Pricing policy
    • Current pricing policy
    • Archive
      • Before January 1, 2019
      • From January 1 to March 1, 2019
      • From March 1, 2019 to February 1, 2020
  • API reference
    • Authentication in the API
    • gRPC
      • Обзор
      • BackupService
      • ClusterService
      • DatabaseService
      • ResourcePresetService
      • UserService
      • OperationService
    • REST
      • Overview
      • Backup
        • Overview
        • get
        • list
      • Cluster
        • Overview
        • addHosts
        • addShard
        • backup
        • create
        • delete
        • deleteHosts
        • deleteShard
        • enableSharding
        • get
        • getShard
        • list
        • listBackups
        • listHosts
        • listLogs
        • listOperations
        • listShards
        • move
        • rescheduleMaintenance
        • resetupHosts
        • restartHosts
        • restore
        • start
        • stop
        • streamLogs
        • update
      • Database
        • Overview
        • create
        • delete
        • get
        • list
      • ResourcePreset
        • Overview
        • get
        • list
      • User
        • Overview
        • create
        • delete
        • get
        • grantPermission
        • list
        • revokePermission
        • update
      • Operation
        • Overview
        • get
  • Questions and answers
    • General questions
    • Questions about MongoDB
    • All questions on the same page
  1. Step-by-step instructions
  2. How to manage shards

How to manage shards

  • Enable sharding
  • List shards in a cluster
  • Add a shard
  • Delete a shard

You can enable sharding for clusters that have MongoDB version 4.0 or higher. You can also add and configure individual shards.

Alert

Once sharding is enabled, the only right way to access the database is over the mongos hosts that store and update shard data. Don't forget to change the host addresses in your app code.

Make sure that your shards consist of at least 3 hosts to ensure higher availability. We don't recommend sharding small collections: query processing is faster with a standard replica cluster.

Enable sharding

Using the Managed Service for MongoDB interface, you can quickly create a MongoDB sharding infrastructure: the mongos and mongocfg hosts needed to run the sharded database.

To learn how to directly shard your MongoDB database and collections, see Sharding collections MongoDB.

Management console
API
  1. Go to the folder page and select Managed Service for MongoDB.

  2. Click the name of a cluster and open the Shards tab.

  3. Click Enable.

  4. Configure the mongocfg and mongos hosts that should provide access to the sharded data.

    To ensure continuous access to your data, Managed Service for MongoDB lets you create at least 3 mongocfg hosts and 2 mongos hosts.

  5. Click Enable sharding.

The cluster update starts. This operation creates the requested mongocfg and mongos hosts as well as the first shard of the cluster.

You can enable sharding for the cluster using the enableSharding method.

List shards in a cluster

Management console
API
  1. Go to the folder page and select Managed Service for MongoDB.

  2. Click the name of a cluster and open the Shards tab.

To list the shards in a cluster, use the listShards method.

Add a shard

The number of shards in Managed Service for MongoDB clusters is limited by the CPU and RAM quotas available to DB clusters in your cloud. To check the resources in use, open the Quotas page and find the Yandex Managed Service for MongoDB block.

Management console
API
  1. Go to the folder page and select Managed Service for MongoDB.
  2. Click on the name of the cluster you need and go to the Hosts tab.
  3. Click Add shard.
  4. Enter a name for the shard and add the desired number of hosts.
  5. Click Create shard.

To add a host to the cluster, use the addHosts method.

Delete a shard

You can delete a shard from a MongoDB cluster provided that it's not the only shard in it. To replace the only shard in a cluster, first create a new shard and then remove the old one.

Management console
API
  1. Go to the folder page and select Managed Service for MongoDB.

  2. Click on the name of a cluster and open the Shards tab.

  3. Click in the line of the desired host and select Delete.

Use the deleteHosts method to delete a host.

In this article:
  • Enable sharding
  • List shards in a cluster
  • Add a shard
  • Delete a shard
Language
Careers
Privacy policy
Terms of use
© 2021 Yandex.Cloud LLC