[SERVER-4098] Sharding: Unable to Upsert when shard key is in an embedded doc Created: 19/Oct/11  Updated: 29/Feb/12  Resolved: 01/Nov/11

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

Type: Bug Priority: Major - P3
Reporter: Vinaykr Assignee: Mathias Stearn
Resolution: Duplicate Votes: 0
Labels: sharding, update
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 10.04 LTS (Lucid Lynx)


Issue Links:
Duplicate
duplicates SERVER-3657 Don't treat updates without upsert as... Closed
Operating System: Linux
Participants:

 Description   

I am using 2.0 release of mongodb in a setup with 4 shards. I created a test collection with following data:
mongos> db.test1.find()
{ "_id" :

{ "a" : 1, "b" : 1 }

, "c" : 3 }
{ "_id" :

{ "a" : 1, "b" : 2 }

, "c" : 3 }
{ "_id" :

{ "a" : 1, "b" : 3 }

, "c" : 3 }
{ "_id" :

{ "a" : 1, "b" : 4 }

, "c" : 3 }

I sharded the collection with shard key: "_id" which worked fine. Even new inserts are working fine after sharding but "upserts" are not working.
For example , following command:
$collection->update(
array('_id' => array('a' => 1, 'b' => 3)),
array('c' => array('$inc' => 1)),
array('upsert' => true, 'safe' => true)
);

results in this error: ** EXCEPTION: can't upsert something without valid shard key

I am using PHP 1.2.3 extension to connect to mongodb.

Above error can be reproduced also when I use "_id.a" as a shard key rather than "_id".



 Comments   
Comment by Mathias Stearn [ 01/Nov/11 ]

This is fallout from SERVER-3657 and will be fixed at the same time

Comment by Ronny Kwon [ 31/Oct/11 ]

it seems that we have the same issue. We have 3 mongoS and mongo C with 2 replica (one primary and two slaves)
the upsert throws an exception :
MongoDB.Driver.MongoSafeModeException: Safemode detected an error 'Can't modify shard key's value fieldk for collection: mydb.cachedItems'. (Response was

{ "err" : "Can't modify shard key's value fieldk for collection:mydb.cachedItems", "code" : 13123, "n" : 0, "ok" : 1.0 }

).

Comment by Vinaykr [ 28/Oct/11 ]

any updates on this? Was anybody able to repro it?
Thanks.

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