mongodb/mongo-java-driver — pull request #153 by hoffrocket (2013-11-19 20:23:52+00:00)
Title: fix for DuplicateKey Exception without code

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:

```json
{
"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"
]
}
```