Investigate changes in SERVER-72121: Add $top/$bottom/$topN/$bottomN as expressions

XMLWordPrintableJSON

    • Type: Investigation
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Developer Tools

      Original Downstream Change Summary

      New expressions for getting top/bottom part of an array

      Description of Linked Ticket

      It is rather awkward that to get topN array elements, you would do $sortArray+$slice while there's topN accumulator available.

      Proposing: 

      $topN: {input: <expression resolving to array>, n: <n expression>, sortBy: <spec>}

      e.g.:

      [
        {
          $set: {
            topThreeOptions: {
              $topN: {
                input: "$options",
                n: 3,
                sortBy: { votes: -1 },
              },
            },
            fiveWatchersAZ: {
              $topN: {
                input: "$watchers",
                n: 5,
                sortBy: 1
              },
            },
          },
        },
      ]

            Assignee:
            Unassigned
            Reporter:
            Backlog - Core Eng Program Management Team
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: