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

Write command write concerns parameter w should be validated >= 0

    • Replication
    • ALL
    • Hide
      //
      // Ensures that mongod respects the batch write protocols
      //
      
      var collectionName = "batch_write_protocol";
      var coll = db.getCollection(collectionName);
      
      jsTest.log("Starting insert tests...");
      
      coll.remove({});
      
      var request;
      var result;
      
      // Drop collection
      coll.dropIndexes();
      coll.drop();
      
      request = {insert : collectionName, documents: [{a:1}], writeConcern:{w:-100}, ordered:true};
      result = coll.runCommand(request)
      assert.eq(0, result.ok);
      assert.eq('number', typeof result.code);
      assert.eq('string', typeof result.errmsg);
      
      request = {update : collectionName, updates: [
      	{q: {a:1}, u: {$set: {a:1}}, upsert:true}
      ], writeConcern:{w:-100}, ordered:true};
      result = coll.runCommand(request)
      assert.eq(0, result.ok);
      assert.eq('number', typeof result.code);
      assert.eq('string', typeof result.errmsg);
      
      request = {delete : collectionName, deletes: [
      	{q:{a:1}, limit:0}
      ], writeConcern:{w:-100}, ordered:true};
      result = coll.runCommand(request)
      assert.eq(0, result.ok);
      assert.eq('number', typeof result.code);
      assert.eq('string', typeof result.errmsg);
      
      Show
      // // Ensures that mongod respects the batch write protocols // var collectionName = "batch_write_protocol" ; var coll = db.getCollection(collectionName); jsTest.log( "Starting insert tests..." ); coll.remove({}); var request; var result; // Drop collection coll.dropIndexes(); coll.drop(); request = {insert : collectionName, documents: [{a:1}], writeConcern:{w:-100}, ordered: true }; result = coll.runCommand(request) assert .eq(0, result.ok); assert .eq( 'number' , typeof result.code); assert .eq( 'string' , typeof result.errmsg); request = {update : collectionName, updates: [ {q: {a:1}, u: {$set: {a:1}}, upsert: true } ], writeConcern:{w:-100}, ordered: true }; result = coll.runCommand(request) assert .eq(0, result.ok); assert .eq( 'number' , typeof result.code); assert .eq( 'string' , typeof result.errmsg); request = {delete : collectionName, deletes: [ {q:{a:1}, limit:0} ], writeConcern:{w:-100}, ordered: true }; result = coll.runCommand(request) assert .eq(0, result.ok); assert .eq( 'number' , typeof result.code); assert .eq( 'string' , typeof result.errmsg);

      When using a write command with write concern w it allows for negative values. They seem to be ignored. Not sure this is expected behavior.

            Assignee:
            backlog-server-repl [DO NOT USE] Backlog - Replication Team
            Reporter:
            christkv Christian Amor Kvalheim
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: