Shard a previously unsharded MongoDB collection and choose an appropriate shard key with sh.shardCollection()

domain: mongodb.com · 5 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Analyze query patterns and pick a shard key field (or compound key) balancing high cardinality, even value frequency, and non-monotonic write distribution
  2. Create a supporting index on the shard key field(s) if one doesn't already exist, since shardCollection requires it
  3. Enable sharding on the database with sh.enableSharding(<db>) if it isn't already enabled
  4. Run sh.shardCollection("<db>.<collection>", { <shardKeyField>: 1 }) — or { field: "hashed" } for a hashed shard key — to shard the collection
  5. Monitor initial chunk distribution and the balancer via sh.status() to confirm chunks spread evenly across shards

Known gotchas

Related routes

Reshard a MongoDB sharded collection with reshardCollection
mongodb · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans