Uploaded image for project: 'Drivers'
  1. Drivers
  2. DRIVERS-2148

Crud spec claims only one of writeError/writeConcernError will be populated at a time

    XMLWordPrintableJSON

Details

    • Icon: Spec Change Spec Change
    • Resolution: Unresolved
    • Icon: Major - P3 Major - P3
    • None
    • CRUD
    • None
    • Needed

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            patrick.freed@mongodb.com Patrick Freed
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: