title: How to get argmax/argmin of multiple fields simultaneously in mongodb?
body: <p>Here's the data example I'm working with.</p>
  <pre class="lang-py prettyprint-override"><code>[
    {
      &quot;uid&quot;: &quot;111&quot;,
      &quot;a&quot;: 1,
      &quot;b&quot;: 3,
      &quot;c&quot;: 1,
      
    },
    {
      &quot;uid&quot;: &quot;222&quot;,
      &quot;a&quot;: 2,
      &quot;b&quot;: 2,
      &quot;c&quot;: 2
    },
    {
      &quot;uid&quot;: &quot;333&quot;,
      &quot;a&quot;: 3,
      &quot;b&quot;: 1,
      &quot;c&quot;: 3
    }
  ]
  </code></pre>
  <p>Then I want to perform <code>argmax</code> on fields &quot;a&quot; and &quot;b&quot;, and <code>argmin</code> on field &quot;c&quot; and return the <code>&quot;uid&quot;</code> as the result.</p>
  <p>For example:</p>
  <p>For &quot;a&quot;, it's maximum value is 3, the corresponding &quot;uid&quot; is &quot;333&quot;, so <code>argmax</code> of &quot;a&quot; should be <code>&quot;uid&quot; : &quot;333&quot;</code>.</p>
  <p>The question is what query should be executed so that I can get the result as below?</p>
  <pre class="lang-py prettyprint-override"><code>[
    {
      &quot;argmax_of_a&quot;: &quot;333&quot;,
      &quot;argmax_of_b&quot;: &quot;111&quot;,
      &quot;argmin_of_c&quot;: &quot;111&quot;,
    }
  ]
  </code></pre>
  <p>Here's the code snipped I'm playing with <a href="https://mongoplayground.net/p/gEDuHd-aCiZ" rel="nofollow noreferrer">https://mongoplayground.net/p/gEDuHd-aCiZ</a></p>
  <p>I can find someway to get <code>argmax/argmin</code> of one specific field, but I have no idea how to work on multiple fields simultaneously.</p>
  <p>Thanks in advance!</p>