Package com.mongodb

Class MongoCommandException

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
MongoNodeIsRecoveringException, MongoNotPrimaryException, MongoQueryException

public class MongoCommandException extends MongoServerException
An exception indicating that a command sent to a MongoDB server returned a failure.
Since:
2.13
  • Constructor Details

    • MongoCommandException

      public MongoCommandException(BsonDocument response, ServerAddress address)
      Construct a new instance with the CommandResult from a failed command
      Parameters:
      response - the command response
      address - the address of the server that generated the response
  • Method Details

    • getErrorCode

      public int getErrorCode()
      Gets the error code associated with the command failure.
      Returns:
      the error code
    • getErrorCodeName

      public String getErrorCodeName()
      Gets the name associated with the error code.
      Overrides:
      getErrorCodeName in class MongoServerException
      Returns:
      the error code name, which may be the empty string
      Since:
      3.8
      Since server release
      3.4
    • getErrorMessage

      public String getErrorMessage()
      Gets the error message associated with the command failure.
      Returns:
      the error message
    • getResponse

      public BsonDocument getResponse()
      Gets the full server response document describing the error.
      Returns:
      the full response to the command failure.
      Since:
      4.8