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

Finalizer for group()

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.1.1
    • Affects Version/s: None
    • Component/s: Usability
    • Labels:
      None

      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.

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

              Created:
              Updated:
              Resolved: