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

Custom Sort Function

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Duplicate
    • Affects Version/s: 2.0.0
    • Fix Version/s: None
    • Component/s: JavaScript, Querying
    • Labels:
      None

      Description

      Similar concept to SERVER-4079. Also related to the needs behind SERVER-458.

      Allow a custom compare function for sorting.

      db.people.find().sort((_foo_bar_baz: function(a, b) {return (a.foo + a.bar + a.baz) - (b.foo + b.bar + b.baz);}})

      This might also make sense (in addition to the previous syntax, not instead).
      db.people.find().sort(function(a, b)

      {return (a.foo + a.bar + a.baz) - (b.foo + b.bar + b.baz);}

      )

      I keep wanting this. One case that keeps popping up is sorting tabular data. Often times columns are computed from the contents of a couple of fields and the best sort order in the mind of the user will not actually have a simple relationship to any of the stored fields. The current workaround is to store pre-computed fields where possible, and disable sorting where this is not possible (or not practical), but precomputed fields are often not a good option (especially when the sort is rare).

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: