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

Remove justOne, with sharding, fails when specifying a comparison query operator

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying, Sharding
    • Labels:
    • Fully Compatible
    • ALL
    • Hide
      var st = new ShardingTest({name: "singleNode", shards: 1, chunksize: 1});
      st.s.adminCommand({enableSharding: "test"});
      st.s.getDB("test").abc.ensureIndex({a: 1});
      st.s.adminCommand({shardCollection: "test.abc", key: {a: 1}});
      for (var i=0; i<10; i++) {
          st.s.getDB("test").abc.insert({a: i});
      }
      st.s.getDB("test").abc.remove({a: {$eq: 6}},{justOne: true});
      st.s.getDB("test").abc.remove({a: 9}, {justOne: true});
      st.s.getDB("test").abc.remove({a: {$gte: 6}},{justOne: true});
      st.stop();
      
      Show
      var st = new ShardingTest({name: "singleNode" , shards: 1, chunksize: 1}); st.s.adminCommand({enableSharding: "test" }); st.s.getDB( "test" ).abc.ensureIndex({a: 1}); st.s.adminCommand({shardCollection: "test.abc" , key: {a: 1}}); for ( var i=0; i<10; i++) { st.s.getDB( "test" ).abc.insert({a: i}); } st.s.getDB( "test" ).abc.remove({a: {$eq: 6}},{justOne: true }); st.s.getDB( "test" ).abc.remove({a: 9}, {justOne: true }); st.s.getDB( "test" ).abc.remove({a: {$gte: 6}},{justOne: true }); st.stop();

      To remove a document in a sharded collection, using the justOne option, the shard key is required. This works for the equality operator. Specify a comparison operator and it fails, i.e., $gte, $lt, with the following error:

      WriteResult({
      	"nRemoved" : 0,
      	"writeError" : {
      		"code" : 61,
      		"errmsg" : "delete { q: { a: { $gte: 6.0 } }, limit: 1 } does not contain _id or shard key for pattern { a: 1.0 }"
      	}
      })
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            jonathan.abrahams Jonathan Abrahams
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: