[SERVER-34877] findAndModify with upsert allows creating shard keys greater than 512 bytes Created: 07/May/18  Updated: 27/Oct/23  Resolved: 15/Sep/20

Status: Closed
Project: Core Server
Component/s: Sharding, Write Ops
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Asya Kamsky Assignee: Katya Kamenieva
Resolution: Gone away Votes: 0
Labels: ShardingRoughEdges, qexec-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-42368 Remove max shard key value size limit Closed
related to SERVER-42646 Cap splitVector response at max BSONO... Closed
is related to SERVER-42368 Remove max shard key value size limit Closed
Operating System: ALL
Steps To Reproduce:

sh.shardCollection("test.foo", {shardkey:1});
db.foo.insert({shardkey:"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"}) /* errors correctly */
db.foo.update({shardkey:"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"},{$set:{shardkey:"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"}},{upsert:true}) /* errors correctly */
db.foo.findAndModify({query: {shardkey:"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"}, update: {$set:{shardkey:"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"}}, upsert:true}) /* succeeds */
Object.bsonsize(db.foo.findOne({},{_id:0}))
521   :( 

 

Participants:
Case:

 Description   

I was able to insert a document with combined shard key value > 512 by using findAndModify with query for that shard key value and then upsert:true and update which sets those fields again.

The check for shard key > 512 seems to get bypassed.

 



 Comments   
Comment by Craig Homa [ 15/Sep/20 ]

Closing as this problem has gone away due to the restriction being removed in 4.4.

Ref: SERVER-42368 for more detail on how this was fixed.

Comment by Asya Kamsky [ 11/Feb/20 ]

Turns out this isn't an issue anymore for 4.4 as there is a different way to limit the size of the result from splitVector.

 

This ticket should be just about what to do in 4.2 (and 4.0).

 

Comment by Sheeri Cabral (Inactive) [ 30/Jan/20 ]

Is this something query can fix by throwing an error? kateryna.kamenieva

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