[SERVER-5710] Update may result in doc without shard key Created: 25/Apr/12  Updated: 11/Jul/16  Resolved: 16/Jan/13

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: 2.4.0-rc0

Type: Bug Priority: Critical - P2
Reporter: Scott Hernandez (Inactive) Assignee: Alberto Lerner
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
related to SERVER-7379 Immutable shardkey becomes mutable Closed
related to SERVER-6835 Sharding edge case upserts documents ... Closed
Operating System: ALL
Participants:

 Description   

If you include the shard-key in the query, but it is removed in the update operations, then the resulting inserted document will not contain the shard key, and will be lost to the sharded system queries.

Mongos should probably build the possibly inserted document to verify the shard-key exists in it before sending the update to the shard.

Take these examples

> db.s.update({shardkey:1}, {$unset: {shardkey:1}, $set: {otherfield : 5}}, true)
// other example
> db.s2.update({"embedded.key":1}, {$set : {embedded:{not_key:1}}}, true)



 Comments   
Comment by auto [ 16/Jan/13 ]

Author:

{u'date': u'2013-01-16T15:36:40Z', u'email': u'alerner@10gen.com', u'name': u'Alberto Lerner'}

Message: SERVER-5710 Changed KeyPattern.hasField() sematics to consider dotted field prefixes.
Branch: master
https://github.com/mongodb/mongo/commit/fd1bc4895b51dc65185ac5fa633bb0435860b936

Comment by Randolph Tan [ 30/Nov/12 ]

Current state of master branch, commit 5a4b6a0acc92c171e7b8fd7fecd26585e76b60be:

First example fails with: Can't modify shard key's value. -> fixed
Second example still gets inserted -> bug

Comment by Scott Hernandez (Inactive) [ 25/Apr/12 ]

Probably better to actually move this check to the shard by simply not allow writing to any data which that shard does not own.

On sharded connections this should enforce that the shard owns the doc, by shard-key, before the write is allowed. On non-sharded connections this should let everything pass.

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