summaryrefslogtreecommitdiff
path: root/src/mongo/client/dbclient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/client/dbclient.cpp')
-rw-r--r--src/mongo/client/dbclient.cpp18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/mongo/client/dbclient.cpp b/src/mongo/client/dbclient.cpp
index 64161cb0708..88abdb77a83 100644
--- a/src/mongo/client/dbclient.cpp
+++ b/src/mongo/client/dbclient.cpp
@@ -500,11 +500,19 @@ namespace mongo {
return getLastErrorString( info );
}
- string DBClientWithCommands::getLastErrorString( const BSONObj& info ) {
- BSONElement e = info["err"];
- if( e.eoo() ) return "";
- if( e.type() == Object ) return e.toString();
- return e.str();
+ string DBClientWithCommands::getLastErrorString(const BSONObj& info) {
+ if (info["ok"].trueValue()) {
+ BSONElement e = info["err"];
+ if (e.eoo()) return "";
+ if (e.type() == Object) return e.toString();
+ return e.str();
+ } else {
+ // command failure
+ BSONElement e = info["errmsg"];
+ if (e.eoo()) return "";
+ if (e.type() == Object) return "getLastError command failed: " + e.toString();
+ return "getLastError command failed: " + e.str();
+ }
}
const BSONObj getpreverrorcmdobj = fromjson("{getpreverror:1}");