Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-9027

Using DBRef as shard key not working anymore in 2.2.0+

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Fixed
    • Affects Version/s: 2.2.0, 2.2.3, 2.4.0
    • Fix Version/s: 2.2.4, 2.4.2, 2.5.0
    • Component/s: Sharding
    • Labels:
      None
    • Backwards Compatibility:
      Fully Compatible
    • Operating System:
      ALL

      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.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: