61 — ShardKeyNotFound

shardingwrite

The shard key field is missing from the document

What is happening?

ShardKeyNotFound is returned when a document being inserted or updated in a sharded collection does not contain the shard key field, or the shard key field is set to null when the collection does not allow it. Every document in a sharded collection must include the shard key so MongoDB can route it to the correct shard.

Common causes

  1. Inserting a document without the shard key field
  2. Application code omitting the shard key in a document transformation
  3. ORM or driver not including the shard key field on insert
  4. Attempting to set the shard key field to null on a collection that disallows it

Diagnostic Steps