[SERVER-3940] Passing a complete document to update can break shard key immutability. Created: 24/Sep/11  Updated: 11/Jul/16  Resolved: 17/Jan/13

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 1.8.2, 2.0.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Bernie Hackett Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File mutable.js    
Issue Links:
Related
is related to SERVER-7379 Immutable shardkey becomes mutable Closed
Operating System: ALL
Participants:

 Description   

Shard keys are supposed to be immutable. This is enforced during update when using an update modifier like $set but not when passing an entire document:

mongos> db.runCommand({shardcollection: 'foo.things', key:

{'foobar': 1}

, unique: true})

{ "collectionsharded" : "foo.things", "ok" : 1 }

...
mongos> db.things.find()

{ "_id" : ObjectId("4e7d176c3c3472e653777dce"), "foobar" : 123 }

mongos> db.things.update(

{'foobar': 123}

, {'$set': {'foobar': 456}})
Can't modify shard key's value fieldfoobar for collection: foo.things
mongos> doc = db.things.findOne()

{ "_id" : ObjectId("4e7d176c3c3472e653777dce"), "foobar" : 123 }

mongos> doc.foobar = 456
456
mongos> db.things.save(doc)
mongos> db.things.find()

{ "_id" : ObjectId("4e7d176c3c3472e653777dce"), "foobar" : 456 }

See the attached js for an example using update directly (without upsert).



 Comments   
Comment by Eliot Horowitz (Inactive) [ 17/Jan/13 ]

There is a related case not fully fixed yet: SERVER-7379

Comment by Eliot Horowitz (Inactive) [ 17/Jan/13 ]

this was fixed, just can't remember the ticket

Generated at Thu Feb 08 03:04:29 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.