Docs Menu

Shard a Global Collection for Global Writes in Data Explorer

On this page

  • Required Roles
  • Considerations
  • Procedure
Note
  • Global writes are only supported on global clusters, which require a cluster tier of M30 or greater.
  • This document assumes prior knowledge of sharding semantics. Review the Sharding documentation before continuing with this tutorial.

In sharded clusters, you can create zones of sharded data based on the shard key. Your zones can segment data based on geographic area. For a complete tutorial on sharding based on geographic area, see Segmenting Data by Location.

The Atlas Data Explorer only supports sharding Global Write collections inside of a global cluster. To shard non-Global-Write collections, you must use mongosh or application code. To learn more, see Deploy a Sharded Cluster.

You must have the Project Owner or Organization Owner role for the cluster's Atlas project to shard a collection for Global Writes in the Data Explorer.

Review the restrictions and compatibility requirements for Sharding Collections for Global Writes before beginning this procedure.

You can configure Online Archive to move infrequently accessed data from your Atlas cluster to a MongoDB-managed read-only Data Lake instead of sharding your collection or upgrading your cluster tier. To learn more about Online Archive, see Archive Data.

After selecting a shard key via the Data Explorer, Atlas attempts to shard the target collection. During this period, make sure that no user manually shards the collection. If Atlas detects that the target collection was sharded with a different key than that selected via the Data Explorer, Atlas stops the procedure and displays a warning for that collection in the Data Explorer. You can Click Unmanage Collection to clear the warning. This removes the collection from Atlas management while leaving the underlying collection and the manually chosen shard key intact.

Starting in MongoDB 4.2, you can update a document’s shard key value unless the shard key field is the immutable _id field. To learn more, see Change a Document’s Shard Key Value.

In MongoDB 4.0 and earlier, you cannot update the value of a shard key field in an existing document in a Global Writes-enabled collection.

To shard a collection in a Global Cluster:

1
2
3
4
5
6

You can choose one of the following:

Default
Atlas uses the document that specifies the field or fields as the shard key.
Use unique index as the shard key
Atlas uses the underlying index to enforce a unique constraint on the shard key of the Global Collection.
Use hashed index as the shard key

Atlas distributes the sharded data evenly by hashing the second field of the shard key. This option is only available for Atlas clusters running MongoDB v4.4 or later.

You can optionally select Pre-split data for even distribution to specify whether to perform initial chunk creation and distribution for an empty or non-existing collection based on the defined zones and zone ranges for the collection.

If you select the Pre-split data for even distribution option, you can also specify the minimum number of chunks to create initially when sharding an empty collection with a hashed shard key. Initial chunk distribution allows Atlas to setup zoned sharding quickly. The number of chunks the Atlas creates depends on the number of zones that you define. By default, Atlas creates one chunk per location code and distributes chunks evenly across all shards.

To learn more about these options, see Global Cluster Sharding Reference.

7

Atlas displays the compound shard key near the top of the Global Writes tab after configuring the collection.

Give Feedback
MongoDB logo
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.