...
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.
sheeri.cabral commented on Tue, 22 Oct 2019 21:20:52 +0000: I didn't investigate! This was a simple test on my laptop in a VirtualBox environment. I have re-created the test environment and the same data with the same tests: On a 3-node replica set, I tried writeConcern values of: majority, 1, 2,3, 4, 0, -1, -2, -2147483648, -2147483649, 2147483648, 2147483649, -2147483647 and 2147483647. The results: Everything was accepted and wrote a value 0 (gave null writeResult), and 4 and 2147483647 gave "not enough data-bearing nodes"). No timeout this time. "opWriteConcernCounters" : { "insert" : { "wmajority" : NumberLong(1), "wnum" : { "-2147483648" : NumberLong(4), "-2147483647" : NumberLong(1), "-2" : NumberLong(1), "-1" : NumberLong(1), "0" : NumberLong(1), "1" : NumberLong(1), "2" : NumberLong(1), "3" : NumberLong(1), "4" : NumberLong(1), "2147483647" : NumberLong(1) }, judah.schvimer commented on Fri, 18 Oct 2019 15:58:52 +0000: One clarification question: you said w:3 timed out. Had you stopped one of the three nodes in the set? Why did it time out? sheeri.cabral commented on Fri, 18 Oct 2019 15:17:39 +0000: On a 3-node replica set, I tried writeConcern values of: majority, 1, 2,3, 4, 0, -1, -2, -2147483648, -2147483649, 2147483648, 2147483649, -2147483647 and 2147483647. The results: Everything was accepted and wrote a value except 3 (timed out) and 0 (gave null writeResult), and 4 and 2147483647 gave "not enough data-bearing nodes") (I also tried other values from 2147483640-2147483646 and got the same error). So it looks like, up to a point, it just says "not enough data bearing nodes" and after that it MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: "majority", wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1 }) MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: 1, wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1 }) MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: 2, wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1 }) MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: 3, wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1, "writeConcernError" : { "code" : 64, "codeName" : "WriteConcernFailed", "errInfo" : { "wtimeout" : true }, "errmsg" : "waiting for replication timed out" } }) MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: 4, wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1, "writeConcernError" : { "code" : 100, "codeName" : "CannotSatisfyWriteConcern", "errmsg" : "Not enough data-bearing nodes" } }) MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: 0, wtimeout: 5000 } } ) WriteResult({ }) MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: -1, wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1 }) MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: -2, wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1 }) MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: -2147483648, wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1 }) MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: -2147483649, wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1 }) MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: 2147483649, wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1 }) MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: 2147483648, wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1 }) MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: 2147483647, wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1, "writeConcernError" : { "code" : 100, "codeName" : "CannotSatisfyWriteConcern", "errmsg" : "Not enough data-bearing nodes" } }) MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: -2147483647, wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1 } And db.serverStatus() shows: "opWriteConcernCounters" : { "insert" : { "wmajority" : NumberLong(775177), "wnum" : { "-2147483648" : NumberLong(4), "-2" : NumberLong(1), "-1" : NumberLong(1), "0" : NumberLong(1), "1" : NumberLong(1), "2" : NumberLong(1), "3" : NumberLong(1) }, "wtag" : { }, "none" : NumberLong(8) }, I also tried 'majority' without quotes, "y", "" and null to see what I'd get - and all except "" had an error, though different ones: MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: majority, wtimeout: 5000 } } ) 2019-10-18T15:08:01.775+0000 E QUERY [thread1] ReferenceError: majority is not defined : @(shell):1:96 MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: "y", wtimeout: 5000 } } ) WriteResult({ "nInserted" : 1, "writeConcernError" : { "code" : 79, "codeName" : "UnknownReplWriteConcern", "errmsg" : "No write concern mode named 'y' found in replica set configuration" } }) MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: , wtimeout: 5000 } } ) 2019-10-18T15:15:46.400+0000 E QUERY [thread1] SyntaxError: expected expression, got ',' @(shell):1:98 MongoDB Enterprise m103-repl:PRIMARY> db.products.insert( { item: "envelopes", qty : 100, type: "Clasp" }, { writeConcern: { w: "", wtimeout: 5000 } } ) WriteResult({ }) Here's the output from opWriteConcernCounters: "opWriteConcernCounters" : { "insert" : { "wmajority" : NumberLong(775177), "wnum" : { "-2147483648" : NumberLong(4), "-2147483647" : NumberLong(1), "-2147483646" : NumberLong(1), "-2147483640" : NumberLong(1), "-2" : NumberLong(1), "-1" : NumberLong(1), "0" : NumberLong(2), "1" : NumberLong(1), "2" : NumberLong(1), "3" : NumberLong(1), "4" : NumberLong(1), "2147483640" : NumberLong(1), "2147483641" : NumberLong(1), "2147483645" : NumberLong(1), "2147483647" : NumberLong(1) }, Everything is reflected there - even the writes that had an error. Note that 0 has 2 values, which were from 0 and "", and -2147483648 has 4 values, which correspond to a writeConcern of: -2147483648 -2147483649 2147483648 2147483649 judah.schvimer commented on Mon, 25 Apr 2016 21:18:08 +0000: This still exists. The write commands accept write concern project did not modify any of the writeConcern parsing or validation. ian@10gen.com commented on Mon, 25 Apr 2016 20:37:01 +0000: judah.schvimer can you confirm whether or not this is still an issue?
// // 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);