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

findAndModify with compound index failed on cluster (sharding)

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.4.6
    • Component/s: Querying, Sharding
    • Labels:
      None
    • ALL
    • Hide
      > db.bcs.insert({sid:111,bmonth:"201401"});
      

      The shard key is sid and bmonth.

      > db.bcs.findAndModify({sid:111,bmonth:"201401"},{$inc:{some_field : 1}});
      Sun Nov 17 13:26:31.118 findAndModifyFailed failed: {
          "code" : 13343,
          "ok" : 0,
          "errmsg" : "exception: query for sharded findAndModify must have shardkey"
      } at src/mongo/shell/collection.js:399
      
      > db.runCommand( { findAndModify: "bcs", query: { sid: 111, bmonth:"201401" }, update: { $inc: { some_field: 1 } } } );
      {
          "value" : {
              "_id" : ObjectId("5288a7d8eb982898248ca83a"),
              "sid" : 111,
              "bmonth" : "201401"
          },
          "lastErrorObject" : {
              "updatedExisting" : true,
              "n" : 1
          },
          "ok" : 1
      }
      
      Show
      > db.bcs.insert({sid:111,bmonth: "201401" }); The shard key is sid and bmonth. > db.bcs.findAndModify({sid:111,bmonth: "201401" },{ $inc :{some_field : 1}}); Sun Nov 17 13:26:31.118 findAndModifyFailed failed: { "code" : 13343, "ok" : 0, "errmsg" : "exception: query for sharded findAndModify must have shardkey" } at src/mongo/shell/collection.js:399 > db.runCommand( { findAndModify: "bcs" , query: { sid: 111, bmonth: "201401" }, update: { $inc : { some_field: 1 } } } ); { "value" : { "_id" : ObjectId( "5288a7d8eb982898248ca83a" ), "sid" : 111, "bmonth" : "201401" }, "lastErrorObject" : { "updatedExisting" : true, "n" : 1 }, "ok" : 1 }

      Updating an existing document using findAndModify on shared cluster, when the collection have compound index raise an error: "query for sharded findAndModify must have shardkey". However, with runCommand it works just fine.

            Assignee:
            Unassigned Unassigned
            Reporter:
            oc666 Ofer Cohen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: