|
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)
|
},
|
|
|
|
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
|