[SERVER-12596] writeConcern {} and writeConcern {wtimeout: 1000} treated like {w: 0} Created: 04/Feb/14  Updated: 11/Jul/16  Resolved: 13/Feb/14

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.5.5
Fix Version/s: 2.6.0-rc0

Type: Bug Priority: Major - P3
Reporter: A. Jesse Jiryu Davis Assignee: Randolph Tan
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Major Change
Operating System: ALL
Participants:

 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 }"
		}
	]
}



 Comments   
Comment by Githook User [ 13/Feb/14 ]

Author:

{u'username': u'renctan', u'name': u'Randolph Tan', u'email': u'randolph@10gen.com'}

Message: SERVER-12596 writeConcern {} and writeConcern

{wtimeout: 1000}

treated like

{w: 0}

Branch: master
https://github.com/mongodb/mongo/commit/78b5eeb13142f0d9bcb43e67848d5fec2f29366d

Generated at Thu Feb 08 03:28:59 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.