Skip to content

Commit

Permalink
Merge pull request #1951 from MartinNowak/mongo_errmsg
Browse files Browse the repository at this point in the history
throw useful error message on MongoDB query failures
  • Loading branch information
s-ludwig committed Mar 18, 2018
1 parent c9c01a6 commit ecc603e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions source/vibe/db/mongo/collection.d
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ struct MongoCollection {
foreach (string key, value; bopt)
cmd[key] = value;
auto ret = database.runCommand(cmd);
enforce(ret["ok"].get!double != 0, "findAndModifyExt failed.");
enforce(ret["ok"].get!double != 0, "findAndModifyExt failed: "~ret["errmsg"].opt!string);
return ret["value"];
}

Expand Down Expand Up @@ -276,7 +276,7 @@ struct MongoCollection {
cmd.count = m_name;
cmd.query = query;
auto reply = database.runCommand(cmd);
enforce(reply["ok"].opt!double == 1 || reply["ok"].opt!int == 1, "Count command failed.");
enforce(reply["ok"].opt!double == 1 || reply["ok"].opt!int == 1, "Count command failed: "~reply["errmsg"].opt!string);
switch (reply["n"].type) with (Bson.Type) {
default: assert(false, "Unsupported data type in BSON reply for COUNT");
case double_: return cast(ulong)reply["n"].get!double; // v2.x
Expand Down Expand Up @@ -318,7 +318,7 @@ struct MongoCollection {
cmd.pipeline = pipeline[0];
else cmd.pipeline.args = pipeline;
auto ret = database.runCommand(cmd);
enforce(ret["ok"].get!double == 1, "Aggregate command failed.");
enforce(ret["ok"].get!double == 1, "Aggregate command failed: "~ret["errmsg"].opt!string);
return ret["result"];
}

Expand Down Expand Up @@ -466,7 +466,7 @@ struct MongoCollection {
cmd.dropIndexes = m_name;
cmd.index = name;
auto reply = database.runCommand(cmd);
enforce(reply["ok"].get!double == 1, "dropIndex command failed.");
enforce(reply["ok"].get!double == 1, "dropIndex command failed: "~reply["errmsg"].opt!string);
}

void drop() {
Expand All @@ -477,7 +477,7 @@ struct MongoCollection {
CMD cmd;
cmd.drop = m_name;
auto reply = database.runCommand(cmd);
enforce(reply["ok"].get!double == 1, "drop command failed.");
enforce(reply["ok"].get!double == 1, "drop command failed: "~reply["errmsg"].opt!string);
}
}

Expand Down

0 comments on commit ecc603e

Please sign in to comment.