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