Skip to content

Commit

Permalink
mango: align opts.fields with fields on _explain
Browse files Browse the repository at this point in the history
This is a follow-up to 83e39b6 where the `all_fields` value was
replaced for `[]` to preserve the JSON array type.  The same has to
be done for `fields` in the `opts` nesting object as well -- these
two attributes should behave alike.
  • Loading branch information
pgj committed Sep 12, 2023
1 parent e63b9e6 commit 86df356
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/mango/src/mango_cursor.erl
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ explain(#cursor{} = Cursor) ->
% The value of `r` needs to be translated to an integer
% otherwise `jiffy:encode/1` will render it as an array.
RValue = lists:keyfind(r, 1, Opts1),
Opts =
Opts2 =
case RValue of
{r, R} ->
lists:keyreplace(r, 1, Opts1, {r, list_to_integer(R)});
Expand All @@ -337,6 +337,14 @@ explain(#cursor{} = Cursor) ->
all_fields -> [];
Value -> Value
end,
OptsFields = lists:keyfind(fields, 1, Opts2),
Opts =
case OptsFields of
{fields, all_fields} ->
lists:keyreplace(fields, 1, Opts2, {fields, []});
_ ->
Opts2
end,
CandidateIndexes = extract_candidate_indexes(Cursor),
SelectorHints = extract_selector_hints(Selector),
{
Expand Down Expand Up @@ -1111,7 +1119,7 @@ t_explain_empty(_) ->
db = db,
index = none,
selector = Selector,
opts = [{user_ctx, user_ctx}],
opts = [{user_ctx, user_ctx}, {fields, all_fields}],
limit = limit,
skip = skip,
fields = all_fields,
Expand All @@ -1124,7 +1132,7 @@ t_explain_empty(_) ->
{index, null},
{partitioned, db_partitioned},
{selector, Selector},
{opts, {[]}},
{opts, {[{fields, []}]}},
{limit, limit},
{skip, skip},
{fields, []},
Expand Down Expand Up @@ -1160,7 +1168,7 @@ t_explain_regular(_) ->
db = db,
index = Index,
selector = Selector,
opts = [{user_ctx, user_ctx}],
opts = [{user_ctx, user_ctx}, {fields, Fields}],
limit = limit,
skip = skip,
fields = Fields,
Expand All @@ -1173,7 +1181,7 @@ t_explain_regular(_) ->
{index, index},
{partitioned, db_partitioned},
{selector, Selector},
{opts, {[]}},
{opts, {[{fields, Fields}]}},
{limit, limit},
{skip, skip},
{fields, Fields},
Expand Down

0 comments on commit 86df356

Please sign in to comment.