[JAVA-1054] "err" field is no longer examined to determine if there is a duplicate key error Created: 26/Nov/13  Updated: 24/Jan/14  Resolved: 24/Jan/14

Status: Closed
Project: Java Driver
Component/s: Error Handling
Affects Version/s: 2.11.0
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Duraid Madina Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Duplicate
duplicates JAVA-1081 CommandResult.getException not detect... Closed

 Description   

hoffrocket reports:

We have some error handling code that depends on catching a DuplicateKey exception. We started getting a WriteConcernException instead after upgrading to the 2.11.3 version of the driver from 2.9.3

The problem is that mongoS doesn't return a "code" in the response (at least in the version which we're using: 2.2.3). Previous versions of the driver checked for a string in the "err", but that was removed in 2.11.x.

Do newer versions of mongoS propagate the "code"?

Here's a pull request: https://github.com/mongodb/mongo-java-driver/pull/153

Here's an example of a response:

{
    "err": "E11000 duplicate key error index: foursquare.coll.$_id_  dup key: { : 1 }",
    "errObjects": [
        {
            "code": 11000,
            "connectionId": 1514529,
            "err": "E11000 duplicate key error index: foursquare.coll.$_id_  dup key: { : 1 }",
            "lastOp": {
                "$inc": 9,
                "$ts": 1384877384
            },
            "n": 0,
            "ok": 1.0
        },
        {
            "code": 11000,
            "connectionId": 1866741,
            "err": "E11000 duplicate key error index: foursquare.coll.$_id_  dup key: { : 2 }",
            "lastOp": {
                "$inc": 0,
                "$ts": 0
            },
            "n": 0,
            "ok": 1.0
        }
    ],
    "errs": [
        "E11000 duplicate key error index: foursquare.coll.$_id_  dup key: { : 1 }",
        "E11000 duplicate key error index: foursquare.coll.$_id_  dup key: { : 2 }"
    ],
    "n": 0,
    "ok": 1.0,
    "serverUsed": "/127.0.0.1:27017",
    "shardRawGLE": {
        "shard0/a:27017,b:27017": {
            "code": 11000,
            "connectionId": 1514529,
            "err": "E11000 duplicate key error index: foursquare.coll.$_id_  dup key: { : 1 }",
            "lastOp": {
                "$inc": 9,
                "$ts": 1384877384
            },
            "n": 0,
            "ok": 1.0
        },
        "shard1/c:27017,d:27017": {
            "code": 11000,
            "connectionId": 1866741,
            "err": "E11000 duplicate key error index: foursquare.coll.$_id_  dup key: { : 2 }",
            "lastOp": {
                "$inc": 0,
                "$ts": 0
            },
            "n": 0,
            "ok": 1.0
        }
    },
    "shards": [
        "shard0/a:27017,b:27017",
        "shard1/c:27017,d:27017"
    ]
}



 Comments   
Comment by Jeffrey Yemin [ 24/Jan/14 ]

Sorry, just noticed the duplicate: JAVA-1081. Closing this one out, since work has already started on the other and there are commits that reference the other

Comment by Jeffrey Yemin [ 26/Nov/13 ]

This is interesting. As far as I know, no other drivers check the "err" field in the way that the Java driver used to. While we can consider rolling back the change, the underlying cause is a mongos bug, as mongos should really propagate the code. I talked to a server engineer about this, and we agreed that this will be fixed in server 2.6, as part of the move to the new write commands.

Generated at Thu Feb 08 08:53:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.