Package com.mongodb
Class WriteConcernException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.mongodb.MongoException
com.mongodb.MongoServerException
com.mongodb.WriteConcernException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
DuplicateKeyException
An exception representing an error reported due to a write failure.
Only thrown when using the legacy deprecated API, which is accessed via com.mongodb.MongoClient.getDB
.
For application using the MongoCollection
-based API, write failures can be determined via:
-
Single document writes: a
MongoWriteException
is thrown. -
Bulk document writes: A
MongoBulkWriteException
is thrown.
-
Field Summary
Fields inherited from class com.mongodb.MongoException
TRANSIENT_TRANSACTION_ERROR_LABEL, UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL
-
Constructor Summary
ConstructorDescriptionWriteConcernException
(BsonDocument response, ServerAddress address, WriteConcernResult writeConcernResult) Construct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic int
extractErrorCode
(BsonDocument response) For internal use only: extract the error code from the response to a write command.static String
extractErrorMessage
(BsonDocument response) For internal use only: extract the error message from the response to a write command.int
Gets the error code associated with the write concern failure.Gets the error message associated with the write concern failure.Gets the response to the write operation.Gets the write result.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
-
WriteConcernException
public WriteConcernException(BsonDocument response, ServerAddress address, WriteConcernResult writeConcernResult) Construct a new instance.- Parameters:
response
- the response to the write operationaddress
- the address of the server that executed the operationwriteConcernResult
- the write concern result
-
-
Method Details
-
extractErrorCode
For internal use only: extract the error code from the response to a write command.- Parameters:
response
- the response- Returns:
- the code, or -1 if there is none
-
extractErrorMessage
For internal use only: extract the error message from the response to a write command.- Parameters:
response
- the response- Returns:
- the error message
-
getWriteConcernResult
Gets the write result.- Returns:
- the write result
-
getErrorCode
public int getErrorCode()Gets the error code associated with the write concern failure.- Returns:
- the error code
-
getErrorMessage
Gets the error message associated with the write concern failure.- Returns:
- the error message
-
getResponse
Gets the response to the write operation.- Returns:
- the response to the write operation
-