[SERVER-9027] Using DBRef as shard key not working anymore in 2.2.0+ Created: 20/Mar/13  Updated: 11/Jul/16  Resolved: 22/Mar/13

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: 2.2.0, 2.2.3, 2.4.0
Fix Version/s: 2.2.4, 2.4.2, 2.5.0

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

Issue Links:
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

Prior to 2.2.0, it was possible to use a DBRef as shardkey. Since 2.2.0 and above, this is no longer possible. Inserts and updates fail, complaining that the shardkey has not been fully specified.

Steps to reproduce (run on sharded environment from mongos):

use test;
 
db.users.drop();
db.coll.drop();
 
sh.enableSharding("test");
sh.shardCollection("test.coll", {reference: 1});
 
db.users.insert({"_id": ObjectId("4c48d2c9280e000000004377"), name: "thomas"});
db.coll.insert({reference: new DBRef("users", ObjectId("4c48d2c9280e000000004377")), payload: "abc"});

This worked in 2.0.8 but is failing in 2.2.0+ with this error:

tried to insert object with no valid shard key for { reference: 1.0 } : { _id: ObjectId('51490336840e9d3bae56af43'), reference: { $ref: "users", $id: ObjectId('4c48d2c9280e000000004377') }, payload: "abc" }

This is particularly problematic for users/customers upgrading from 2.0.x that were using a DBRef as their shard key and can't insert any data anymore.

For the updates, there is a work-around in using the _id field instead of the DBRef for the query. But for inserts, this is not possible.



 Comments   
Comment by auto [ 28/Mar/13 ]

Author:

{u'date': u'2013-03-22T17:22:42Z', u'name': u'Scott Hernandez', u'email': u'scotthernandez@gmail.com'}

Message: SERVER-9027: allow dbref shard keys
Branch: v2.4
https://github.com/mongodb/mongo/commit/27b3840145a51d401457da35d54c69dc31d03c43

Comment by auto [ 28/Mar/13 ]

Author:

{u'date': u'2013-03-22T17:22:42Z', u'name': u'Scott Hernandez', u'email': u'scotthernandez@gmail.com'}

Message: SERVER-9027: allow dbref shard keys
Branch: v2.2
https://github.com/mongodb/mongo/commit/d1421e517c41af36cd756f591b913e3c2b3fed76

Comment by Terence Tung [ 27/Mar/13 ]

hi Scott, do you think you have the ETA for the 2.2.4 release by now? thanks!

Comment by Scott Hernandez (Inactive) [ 25/Mar/13 ]

We have not set a new release date for 2.2.4 yet (RC has to come out first – watch here https://jira.mongodb.org/browse/SERVER/fixforversion/12313) since it was pushed back a bit, but this fix should be committed on that branch in the next day (so the nightly RC builds will have it tomorrow night), and the release will follow shortly there after.

Comment by Terence Tung [ 25/Mar/13 ]

hi Scott, any idea when will this fix be available in 2.2.4? thanks!

Comment by auto [ 22/Mar/13 ]

Author:

{u'date': u'2013-03-22T17:22:42Z', u'name': u'Scott Hernandez', u'email': u'scotthernandez@gmail.com'}

Message: SERVER-9027: allow dbref shard keys
Branch: master
https://github.com/mongodb/mongo/commit/a67ea3ac0c570cc738d43494079e2bc284aa5071

Comment by Scott Hernandez (Inactive) [ 21/Mar/13 ]

We are working on a fix, and backports, for this.

Comment by Terence Tung [ 21/Mar/13 ]

hi Randolph and Scott, what is the plan for this bug? would there be a patch for 2.2 or 2.4 to fix this issue? because this bug is blocking us from upgrading our mongodb from 2.0.8 to anything above.

thanks,
TT

Comment by Scott Hernandez (Inactive) [ 20/Mar/13 ]

Extended json should never be used in bson documents, or make it to the server. It is there for tools to convert from json -> bson docs to keep type information which can't be represented native json. Except for DBRef all "$" prefixed field names are illegal, so that would be another bug if extended json got into bson docs on the server.

Comment by Randolph Tan [ 20/Mar/13 ]

Note: The problem is not limited to DBRef but also other extended json notation as well.

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