Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-287

Finalizer for group()

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 1.1.1
    • None
    • Usability
    • None

    Description

      It would be nice if there was an extra finalizer option on the group command. Right now it is difficult to implement an average function using just group(). While this could be done in the calling language, in some cases it is nice to be able to do everything in one place in javascript.

      Example

      db.coll.group(
      {key:"date"
      ,initial:

      {ct:0, sum:0}

      ,reduce: function(doc, out)

      {out.ct++; out.sum += doc.val}

      ,final: function(result)

      {result.sum = result.ct ? result.sum/result.ct : 0}

      })

      Ideally, if the final function returned a non-undefined result it would replace that position in the output, similar to a map function.

      Attachments

        Activity

          People

            mathias@mongodb.com Mathias Stearn
            mathias@mongodb.com Mathias Stearn
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: