DuplicateKeyError

Python (PyMongo)WriteErrorgeneral

Raised when a write attempts to create a duplicate value in a unique index (server error code 11000)

Related Jira Issues

GODRIVER-3954Needs Triage
Implement the ServerError interface for ClientBulkWriteException
h3. *Context* {{ClientBulkWriteException}} does not implement the full {{ServerError}} interface. As a result, {{errors.As(err, &serverErr)}} returns {{false}} for a client bulk write error, and the idiomatic server-error detection path. Its unclear why there wouldn't be parity with {{BulkWriteEception}}. h3. *Definition of done* * Implement {{ServerError}} interface for {{ClientBulkWriteException}} * Update documentation for {{IsDuplicateKeyError}}, {{IsNetworkError}}, and {{IsTimeout}} t
NODE-5659Closed
Driver retries a transaction operation when a DuplicateKeyError is hit
h3. What problem are you facing? I hit this issue in a test where I attempt to insert multiple copies of the same document in a single transaction. I can see that one of the insert operations fails with a DuplicateKeyError, but it seems that when the transaction is run using the driver's `withTransaction` wrapper, it keeps retrying the transaction even though the error shouldn't really be considered "transient" (ie. this operation will always fail no matter what) h3. What driver and relevant
GODRIVER-4009Closed
IsDuplicateKeyError doesn’t work with ClientBulkWriteException
h3. Detailed steps to reproduce the problem? ``` func IsDuplicateKeyError(err error) bool { if se := ServerError(nil); errors.As(err, &se) { return se.HasErrorCode(11000) || // Duplicate key error. se.HasErrorCode(11001) || // Duplicate key error on update. // Duplicate key error in a capped collection. See SERVER-7164. se.HasErrorCode(12582) || // Mongos insert error caused by a duplicate key error. See // SERVER-11493. se.HasErrorCodeWithMessage(16460, " E11000 "