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

writeConcern {} and writeConcern {wtimeout: 1000} treated like {w: 0}

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 2.6.0-rc0
    • 2.5.5
    • Write Ops
    • None
    • Major Change
    • ALL

    Description

      In nightly, hash bffe6421, an insert or update command treats writeConcern {} or {wtimeout: N} like {w: 0}:

      > db.collection.find()
      { "_id" : 1 }
      > // should throw duplicate key error
      > db.runCommand({insert: 'collection', documents: [{_id: 1}], ordered: false, writeConcern: {}})
      { "ok" : 1 }
      > db.runCommand({insert: 'collection', documents: [{_id: 1}], ordered: false, writeConcern: {wtimeout: 1000}})
      { "ok" : 1 }

      I expect these write concerns to be treated like {w: 1}.

      writeConcerns {j: true} and {fsync: true} are treated like {w: 1} as expected.

      The update command behaves the same as insert:

      > db.collection.remove({})
      > db.collection.createIndex({a: 1}, {unique: true})
      > db.collection.insert([{a: 1}, {a: 2}])
      > // show throw duplicate key error
      > db.runCommand({update: 'collection', updates: [{q: {a: 2}, u: {$set: {a: 1}}}], writeConcern: {}})
      { "ok" : 1 }
      > db.runCommand({update: 'collection', updates: [{q: {a: 2}, u: {$set: {a: 1}}}], writeConcern: {wtimeout: 1000}})
      { "ok" : 1 }
      > // had no effect
      > db.collection.find()
      { "_id" : ObjectId("52f05af909990b7219531c91"), "a" : 1 }
      { "_id" : ObjectId("52f05af909990b7219531c92"), "a" : 2 }
      > // works as expected
      > db.runCommand({update: 'collection', updates: [{q: {a: 2}, u: {$set: {a: 1}}}], writeConcern: {j: true}})
      {
      	"ok" : 1,
      	"nModified" : 0,
      	"n" : 0,
      	"writeErrors" : [
      		{
      			"index" : 0,
      			"code" : 11000,
      			"errmsg" : "E11000 duplicate key error index: test.collection.$a_1  dup key: { : 1.0 }"
      		}
      	]
      }

      Attachments

        Activity

          People

            randolph@mongodb.com Randolph Tan
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: