This is an automated email from the ASF dual-hosted git repository.

pgj pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/main by this push:
     new 86df356a8 mango: align `opts.fields` with `fields` on `_explain`
86df356a8 is described below

commit 86df356a8a396a5c165107e6d57f405741257a99
Author: Gabor Pali <[email protected]>
AuthorDate: Mon Sep 11 18:59:59 2023 +0200

    mango: align `opts.fields` with `fields` on `_explain`
    
    This is a follow-up to 83e39b6d 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.
---
 src/mango/src/mango_cursor.erl | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/mango/src/mango_cursor.erl b/src/mango/src/mango_cursor.erl
index 09d84774e..3eedc7383 100644
--- a/src/mango/src/mango_cursor.erl
+++ b/src/mango/src/mango_cursor.erl
@@ -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)});
@@ -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),
     {
@@ -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,
@@ -1124,7 +1132,7 @@ t_explain_empty(_) ->
             {index, null},
             {partitioned, db_partitioned},
             {selector, Selector},
-            {opts, {[]}},
+            {opts, {[{fields, []}]}},
             {limit, limit},
             {skip, skip},
             {fields, []},
@@ -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,
@@ -1173,7 +1181,7 @@ t_explain_regular(_) ->
             {index, index},
             {partitioned, db_partitioned},
             {selector, Selector},
-            {opts, {[]}},
+            {opts, {[{fields, Fields}]}},
             {limit, limit},
             {skip, skip},
             {fields, Fields},

Reply via email to