thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

Data & Analytics · Advanced

Shard Key

The field or fields used to decide which shard stores each document or row.

Definition

A good shard key has high cardinality, distributes writes evenly and matches common query patterns so queries target a single shard. Monotonically increasing keys such as timestamps send all inserts to one shard. Since MongoDB 5.0 a collection can be resharded, but the choice is still critical.

Example

sh.shardCollection('shop.orders', { customerId: 'hashed' })

Exam tip

Avoid monotonically increasing shard keys; use hashed keys or compound keys to spread writes.

Related terms