283 — WouldChangeOwningShard
shardingwrite
An update would move the document to a different shard
What is happening?
WouldChangeOwningShard is returned when an update modifies the shard key value in a way that would move the document from one shard to another. Prior to MongoDB 5.0, changing the shard key value was not allowed. From 5.0 onward, the operation is allowed inside a retryable write or transaction but requires the document to be deleted from the source shard and re-inserted on the target shard.
Common causes
- Updating a field that is part of the shard key
- Upsert creating a document with a different shard key range than the filter
- Application updating a shard key field without using a transaction (pre-5.0)
- Aggregation $merge or $out writing documents to a different shard