-
Type:
Spec Change
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Component/s: CRUD
-
None
-
Needed
A comment above the definition of WriteException states the following:
/** * NOTE: Only one of writeConcernError or writeError will be populated at a time. Your driver must present the offending * error to the user. */
This isn't true, however. On a 3-node replica set, in a collection containing a document with _id: 1, the following command will produce both errors:
db.runCommand({
... insert: "test",
... documents: [ { _id: 1 }],
... writeConcern: {w: 100}
})
output:
{
"n" : 0,
"writeErrors" : [
{
"index" : 0,
"code" : 11000,
"keyPattern" : {
"_id" : 1
},
"keyValue" : {
"_id" : 1
},
"errmsg" : "E11000 duplicate key error collection: test.test index: _id_ dup key: { _id: 1.0 }"
}
],
"ok" : 1,
"writeConcernError" : {
"code" : 100,
"codeName" : "UnsatisfiableWriteConcern",
"errmsg" : "Not enough data-bearing nodes"
}
}
This direction may cause drivers to ignore the other error if they have already discovered one of them.
UnsatisfiableWriteConcern might be the only case in which this is possible, though.