79380172

Date: 2025-01-23 07:33:28
Score: 2
Natty:
Report link

Now after some time and research, I want to follow up and post our solution here. We ended up using the built-in $top accumulator (docs):

{
   $top:
      {
         sortBy: { <field1>: <sort order>, <field2>: <sort order> ... },
         output: <expression>
      }
}

We used sortBy to sort by the absolute of the field's value, maintaining the original sign in the output. For us, this gave us significant performance increase over the original ideas I posted.

Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: user9817468211