Package com.mongodb
Class CommandResult
- java.lang.Object
 - 
- java.util.AbstractMap<K,V>
 - 
- java.util.HashMap<K,V>
 - 
- java.util.LinkedHashMap<String,Object>
 - 
- org.bson.BasicBSONObject
 - 
- com.mongodb.BasicDBObject
 - 
- com.mongodb.CommandResult
 
 
 
 
 
 
 
- 
- All Implemented Interfaces:
 DBObject,Serializable,Cloneable,Map<String,Object>,BSONObject,Bson
public class CommandResult extends 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
 
 
- 
- 
Nested Class Summary
- 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object> 
 - 
 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetErrorMessage()Gets the error message associated with a failed command.MongoExceptiongetException()Utility method to create an exception from a failed command.booleanok()Gets the "ok" field, which is whether this command executed correctly or not.voidthrowOnError()Throws aCommandFailureExceptionif the command failed.- 
Methods inherited from class com.mongodb.BasicDBObject
append, copy, equals, hashCode, isPartialObject, markAsPartialObject, parse, parse, toBsonDocument, toJson, toJson, toJson, toJson, toString 
- 
Methods inherited from class org.bson.BasicBSONObject
containsField, containsKey, get, getBoolean, getBoolean, getDate, getDate, getDouble, getDouble, getInt, getInt, getLong, getLong, getObjectId, getObjectId, getString, getString, putAll, putAll, removeField, toMap 
- 
Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, values 
- 
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putIfAbsent, remove, remove, replace, replace, size 
- 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait 
- 
Methods inherited from interface org.bson.BSONObject
containsField, containsKey, get, keySet, put, putAll, putAll, removeField, toMap 
- 
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putIfAbsent, remove, remove, replace, replace, size 
 - 
 
 - 
 
- 
- 
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 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 aCommandFailureExceptionif the command failed. Otherwise, returns normally.- Throws:
 MongoException- with the exception from the failed command- See Also:
 ok()
 
 - 
 
 -