If there is no _id in the replace spec it is copied from the query. Note that non-upsert updates handle this correctly:
> sh.shardCollection('test.sharded', {_id:1}) { "collectionsharded" : "test.sharded", "ok" : 1 } > db.sharded.runCommand('update', {updates:[{q:{_id:1}, u:{}, upsert: true}]}) { "ok" : 1, "nModified" : 0, "n" : 0, "writeErrors" : [ { "index" : 0, "code" : 61, "errmsg" : "upsert { q: { _id: 1.0 }, u: {}, upsert: true } does not contain shard key for pattern { _id: 1.0 }" } ] } > db.sharded.runCommand('update', {updates:[{q:{_id:1}, u:{}, upsert: false}]}) { "ok" : 1, "nModified" : 0, "n" : 0 }
This should only be allowed if sharded on _id, because replace-style updates preserve _id.
- duplicates
-
SERVER-34971 Improve mongoS targeting of replacement-style updates for collections whose shard key includes _id
- Closed
- is duplicated by
-
SERVER-20635 Write failed with error code 61 and error message 'upsert
- Closed