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.