title: Node.js sorting array with findOne
body: <p>I'm attempting to sort the array from Mongodb, <code>Image</code> elements in time descending order. The date is located within the array.
  This is the current output:</p>
  <pre><code>&quot;address&quot;: &quot;Product Address 1&quot;,
  &quot;town&quot;: &quot;Brighton&quot;,
  &quot;Image&quot;: [
    {
      &quot;price&quot;: 1021,
      &quot;time&quot;: &quot;2020-09-13T12:06:34.079Z&quot;
    },
    {
      &quot;price&quot;: 1022,
      &quot;time&quot;: &quot;2020-09-13T12:18:50.270Z&quot;
    },
    {
      &quot;price&quot;: 1023,
      &quot;time&quot;: &quot;2020-09-13T12:37:22.499Z&quot;
    }
    ]
  </code></pre>
  <p>What I need is for the following element first, followed by the remaining two array elements:</p>
  <pre><code>{
      &quot;price&quot;: 1023,
      &quot;time&quot;: &quot;2020-09-13T12:37:22.499Z&quot;
  }
  </code></pre>
  <p>The code I have is :</p>
  <pre><code>  dbProduct.findOne({
                  productId: productId
            
          },{'image.token':0}).then(dbRes =&gt; {
      
                  if (dbRes !== null) {
                      res.apiSuccess({
                      town: dbRes.town,
                  
  
      county: dbRes.county,
                  postCode: dbRes.postCode,
                  image: dbRes.image
    });
          } else {
              res.apiError(messages.product.not_found);
          }
  </code></pre>
  <p>Any help appreciated. Thanks</p>