From ecc603eca447b97cf26b64ae5a757ad1b633ac6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sun, 15 Oct 2017 23:59:14 +0200 Subject: [PATCH] Merge pull request #1951 from MartinNowak/mongo_errmsg throw useful error message on MongoDB query failures --- source/vibe/db/mongo/collection.d | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/vibe/db/mongo/collection.d b/source/vibe/db/mongo/collection.d index 1f0875ddb2..4edb2ada11 100644 --- a/source/vibe/db/mongo/collection.d +++ b/source/vibe/db/mongo/collection.d @@ -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"]; } @@ -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 @@ -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"]; } @@ -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() { @@ -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); } }