<tfoot id='jESao'></tfoot>

<small id='jESao'></small><noframes id='jESao'>

  1. <legend id='jESao'><style id='jESao'><dir id='jESao'><q id='jESao'></q></dir></style></legend>

    <i id='jESao'><tr id='jESao'><dt id='jESao'><q id='jESao'><span id='jESao'><b id='jESao'><form id='jESao'><ins id='jESao'></ins><ul id='jESao'></ul><sub id='jESao'></sub></form><legend id='jESao'></legend><bdo id='jESao'><pre id='jESao'><center id='jESao'></center></pre></bdo></b><th id='jESao'></th></span></q></dt></tr></i><div id='jESao'><tfoot id='jESao'></tfoot><dl id='jESao'><fieldset id='jESao'></fieldset></dl></div>
    • <bdo id='jESao'></bdo><ul id='jESao'></ul>

      如何获得按“值"降序排序的 map/reduce 结果?值

      时间:2023-09-07
        <i id='Dtvx5'><tr id='Dtvx5'><dt id='Dtvx5'><q id='Dtvx5'><span id='Dtvx5'><b id='Dtvx5'><form id='Dtvx5'><ins id='Dtvx5'></ins><ul id='Dtvx5'></ul><sub id='Dtvx5'></sub></form><legend id='Dtvx5'></legend><bdo id='Dtvx5'><pre id='Dtvx5'><center id='Dtvx5'></center></pre></bdo></b><th id='Dtvx5'></th></span></q></dt></tr></i><div id='Dtvx5'><tfoot id='Dtvx5'></tfoot><dl id='Dtvx5'><fieldset id='Dtvx5'></fieldset></dl></div>
      1. <small id='Dtvx5'></small><noframes id='Dtvx5'>

        <legend id='Dtvx5'><style id='Dtvx5'><dir id='Dtvx5'><q id='Dtvx5'></q></dir></style></legend>

            <tfoot id='Dtvx5'></tfoot>
            • <bdo id='Dtvx5'></bdo><ul id='Dtvx5'></ul>

                <tbody id='Dtvx5'></tbody>

              1. 本文介绍了如何获得按“值"降序排序的 map/reduce 结果?值?如果也使用列表函数可以实现吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我有这样的视图地图和减少:地图:

                I have view map and reduce like this: Map:

                   function(doc) {
                           if(doc.type){
                            var usersLength = doc.users.length;
                            for (var i = 0; i < usersLength ; i++) {
                                    emit([doc.users[i].userid,doc.Service.ownId], 1);
                                }
                            }
                        }
                

                减少:

                 function(keys, values, rereduce)
                    {
                      return sum(values);
                    }
                

                然后像这样调用视图:_design/aaa/_view/getUserId?group=true&group_level=2&startkey=["111111"]&endkey=["111111",{}]

                我可以得到下面的结果集:

                I can get the result set below:

                {"rows":[
                {"key":["111111",""],"value":7},
                {"key":["111111","FFFF26"],"value":1},
                {"key":["111111","FFFF44"],"value":7},
                {"key":["111111","FFFF34"],"value":2}
                ]}
                

                但是,我想让上面的结果集按值"值的降序排序.如果还使用列表功能可以实现吗?预期结果如下:

                However, I want to get the result set above sorted within descending order of the "value" value. if also using list function can achieve that? the following would be expected results:

                {"rows":[
                {"key":["111111",""],"value":7},
                {"key":["111111","FFFF44"],"value":7},
                {"key":["111111","FFFF34"],"value":2},
                {"key":["111111","FFFF26"],"value":1}
                ]}
                

                推荐答案

                如果要对结果集进行排序,则必须按值降序排序,可以使用比较器回调进行排序:

                If you want to sort the result set you have to one that is sorted by value descending you can sort with a comparator callback:

                // ES6 Syntax
                let originalResult = {
                "rows":[
                  {"key":["111111",""],"value":7},
                  {"key":["111111","FFFF26"],"value":1},
                  {"key":["111111","FFFF44"],"value":7},
                  {"key":["111111","FFFF34"],"value":2}
                ]}
                
                let newResult = {
                  rows: originalResult.rows.sort((a, b) => b.value - a.value)
                } 
                

                这篇关于如何获得按“值"降序排序的 map/reduce 结果?值?如果也使用列表函数可以实现吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                    <tbody id='PWOEo'></tbody>

                    <tfoot id='PWOEo'></tfoot>
                    1. <small id='PWOEo'></small><noframes id='PWOEo'>

                      <i id='PWOEo'><tr id='PWOEo'><dt id='PWOEo'><q id='PWOEo'><span id='PWOEo'><b id='PWOEo'><form id='PWOEo'><ins id='PWOEo'></ins><ul id='PWOEo'></ul><sub id='PWOEo'></sub></form><legend id='PWOEo'></legend><bdo id='PWOEo'><pre id='PWOEo'><center id='PWOEo'></center></pre></bdo></b><th id='PWOEo'></th></span></q></dt></tr></i><div id='PWOEo'><tfoot id='PWOEo'></tfoot><dl id='PWOEo'><fieldset id='PWOEo'></fieldset></dl></div>

                        <bdo id='PWOEo'></bdo><ul id='PWOEo'></ul>
                        <legend id='PWOEo'><style id='PWOEo'><dir id='PWOEo'><q id='PWOEo'></q></dir></style></legend>