From 1be1757bbd62e0cc5b4fdf92e38fbe5e97e4d7ea Mon Sep 17 00:00:00 2001 From: JianBo He Date: Thu, 10 Dec 2020 15:29:06 +0800 Subject: [PATCH] fix(mongo): avoid function_caluse while query returned other types --- apps/emqx_auth_mongo/src/emqx_auth_mongo.erl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/emqx_auth_mongo/src/emqx_auth_mongo.erl b/apps/emqx_auth_mongo/src/emqx_auth_mongo.erl index 133bcac70..2ca4a6f54 100644 --- a/apps/emqx_auth_mongo/src/emqx_auth_mongo.erl +++ b/apps/emqx_auth_mongo/src/emqx_auth_mongo.erl @@ -85,10 +85,16 @@ description() -> "Authentication with MongoDB". is_superuser(_Pool, undefined, _ClientInfo) -> false; is_superuser(Pool, #superquery{collection = Coll, field = Field, selector = Selector}, ClientInfo) -> - Row = query(Pool, Coll, maps:from_list(replvars(Selector, ClientInfo))), - case maps:get(Field, Row, false) of - true -> true; - _False -> false + case query(Pool, Coll, maps:from_list(replvars(Selector, ClientInfo))) of + undefined -> false; + {error, Reason} -> + ?LOG(error, "[MongoDB] Can't connect to MongoDB server: ~0p", [Reason]), + false; + Row -> + case maps:get(Field, Row, false) of + true -> true; + _False -> false + end end. replvars(VarList, ClientInfo) ->