How can I get a map/reduce result which is sorted within descending order of the “value” value?if also using list function can achieve that?

后端 未结 1 1637
太阳男子
太阳男子 2021-01-26 10:23

I have view map and reduce like this: Map:

   function(doc) {
           if(doc.type){
            var usersLength = doc.users.length;
            for (var i = 0         


        
1条回答
  •  时光说笑
    2021-01-26 11:09

    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)
    } 
    

    0 讨论(0)
提交回复
热议问题