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

Immutable shardkey becomes mutable

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.5.3
    • Affects Version/s: 2.2.0
    • Component/s: Sharding, Write Ops
    • Labels:
    • Environment:
      linux 64 bit
    • Linux

      I'm using the following shard key

      {"categoryId":1, "store":1, "_id":1}

      For testing purposes I only have one document in the collection:

      mongos> db.offerChange.find()
      { "_id" : 123, "categoryId" : 9881, "store" : "NEW" }

      When I want to update a field, I get correctly an alert "Can't modify shard key's value":

      mongos> db.offerChange.update({"_id":123}, {$set:{"store":"NEWEST"}}, true, false)
      Can't modify shard key's value. field: store: "NEWEST" collection: offerChange.offerChange

      However, I can modify the shard key by executing this:

      mongos> db.offerChange.update({"_id":123}, {"_id":123, "categoryId":9881,"store":"NEWEST"}, true, false)
      mongos> db.offerChange.find()
      { "_id" : 123, "categoryId" : 9881, "store" : "NEWEST" }

      Also, I could call save to change the shard key again (back):

      mongos> db.offerChange.save({"categoryId":9881, "store":"NEW","_id":123})
      mongos> db.offerChange.find()
      { "_id" : 123, "categoryId" : 9881, "store" : "NEW" }

      Now, when I try to add a second shard key field to the query, I get the same but differently expressed correct alert:

      mongos> db.offerChange.update({"_id":123,"store":"NEW"}, {"_id":123, "categoryId":9881,"store":"NEWEST"}, true, false)
      cannot modify shard key for collection offerChange.offerChange, found new value for store

      However, when I replace the second by the third shard key field in the query, the update works again:

      mongos> db.offerChange.update({"_id":123,"categoryId":9881}, {"_id":123, "categoryId":9881,"store":"NEWEST"}, true, false)
      mongos> db.offerChange.find()
      { "_id" : 123, "categoryId" : 9881, "store" : "NEWEST" }

      I asked already in the mongoDB forum but nobody answered so far.

      As I think that's rather a bug than a feature, I opened this bug report.

            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            kay.agahd@idealo.de Kay Agahd
            0 Vote for this issue
            7 Start watching this issue