erroneous error message "valid shard key must be in update object for collection" when updating sharded collection

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: 1.8.2, 2.0.2
    • Component/s: Sharding
    • None
    • Environment:
      Fedora 16 x86_64
    • ALL
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      On an unsharded database you can update a document without having to pass in the _id as a value in the update document. The new document will retain the old _id. For sharded collections if you want to update a document you have to include the _id (or whatever your shard key is) or you will get an error.

      use admin
      db.runCommand(

      {"enablesharding" : "test"}

      );
      db.runCommand( { shardcollection : "test.coll", key : {_id : 1} } );

      use test
      db.coll.insert(

      { "_id": "theid", "num" : 1}

      )
      db.coll.update(

      { "_id": "theid"}

      ,

      {"num" : 2}

      )

      results in:

      valid shard key must be in update object for collection: test.coll

            Assignee:
            Unassigned
            Reporter:
            Joseph Shraibman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: