Package com.mongodb

Class CommandResult

  • All Implemented Interfaces:
    com.mongodb.DBObject, Serializable, Cloneable, Map<String,​Object>, org.bson.BSONObject, org.bson.conversions.Bson

    public class CommandResult
    extends com.mongodb.BasicDBObject
    A simple wrapper to hold the result of a command. All the fields from the response document have been added to this result.
    See Also:
    Serialized Form
    MongoDB documentation
    Database Commands
    • Method Detail

      • ok

        public boolean ok()
        Gets the "ok" field, which is whether this command executed correctly or not.
        Returns:
        true if the command executed without error.
      • getErrorMessage

        @Nullable
        public String getErrorMessage()
        Gets the error message associated with a failed command.
        Returns:
        The error message or null
      • getException

        @Nullable
        public com.mongodb.MongoException getException()
        Utility method to create an exception from a failed command.
        Returns:
        The mongo exception, or null if the command was successful.
      • throwOnError

        public void throwOnError()
        Throws a CommandFailureException if the command failed. Otherwise, returns normally.
        Throws:
        com.mongodb.MongoException - with the exception from the failed command
        See Also:
        ok()