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

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

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 1.8.2, 2.0.2
    • Sharding
    • None
    • Fedora 16 x86_64
    • ALL

    Description

      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

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: