Package com.mongodb
Class DuplicateKeyException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.mongodb.MongoException
com.mongodb.MongoServerException
com.mongodb.WriteConcernException
com.mongodb.DuplicateKeyException
- All Implemented Interfaces:
Serializable
The legacy
WriteConcernException
, thrown when trying to insert or update a document containing a duplicate key.
Only thrown when using the legacy deprecated API, which is accessed via com.mongodb.MongoClient.getDB
.
For application using the MongoCollection
-based API, duplicate key exceptions can be determined via:
-
Single document inserts or updates: a
MongoWriteException
is thrown with aWriteError
in the categoryErrorCategory.DUPLICATE_KEY
. -
Bulk document inserts or updates: A
MongoBulkWriteException
is thrown where one or more of theWriteError
's in the list of errors is in the categoryErrorCategory.DUPLICATE_KEY
.
- Since:
- 2.12
- See Also:
-
Field Summary
Fields inherited from class com.mongodb.MongoException
TRANSIENT_TRANSACTION_ERROR_LABEL, UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL
-
Constructor Summary
ConstructorDescriptionDuplicateKeyException
(BsonDocument response, ServerAddress address, WriteConcernResult writeConcernResult) Construct an instance. -
Method Summary
Methods inherited from class com.mongodb.WriteConcernException
extractErrorCode, extractErrorMessage, getErrorCode, getErrorMessage, getResponse, getWriteConcernResult
Methods inherited from class com.mongodb.MongoServerException
getServerAddress
Methods inherited from class com.mongodb.MongoException
addLabel, addLabels, addLabels, fromThrowable, fromThrowableNonNull, getCode, getErrorLabels, hasErrorLabel, removeLabel
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
DuplicateKeyException
public DuplicateKeyException(BsonDocument response, ServerAddress address, WriteConcernResult writeConcernResult) Construct an instance.- Parameters:
response
- the response from the serveraddress
- the server addresswriteConcernResult
- the write concern result
-