Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for DuplicateKey Exception without code #153

Closed
wants to merge 1 commit into from

Conversation

hoffrocket
Copy link
Contributor

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.

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"
    ]
}

mongoS doesn't return a "code", so we need to check the "err" as well
@jyemin
Copy link
Contributor

jyemin commented Jan 16, 2014

See https://jira.mongodb.org/browse/JAVA-1081. Based on pymongo, I would prefer to use a different algorithm: find the first document in the errObjects array that has an err field equal to the top level one, and grab the code from there.

Would you like to take a stab at fixing it that way, or shall I close?

@jyemin
Copy link
Contributor

jyemin commented Jun 17, 2014

The underlying issue was fixed in scope of https://jira.mongodb.org/browse/JAVA-1081, so I'm going to close this.

@jyemin jyemin closed this Jun 17, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants