title: Mongo $min and $max, or Parallel sort
body: <p>Hi I want to get the <code>min</code> and a <code>max</code> value of a field in my db.</p>
  
  <p>I found this solution which queries and sorts the results:
  <a href="https://stackoverflow.com/questions/10572592/get-max-value-in-mongoose">get max value in mongoose</a>
  I could do this twice and combine it with async.parallel to write it non-blocking. But I guess two db queries may not be the best solution.</p>
  
  <p>The second solution would be to use aggregate. But I don't want to group anything. I only want to use <code>$match</code> to filter (filter criteria are always diff and can be <code>{}</code>) and run the query with all documents in my collection.</p>
  
  <p><a href="http://docs.mongodb.org/manual/reference/operator/aggregation/min/" rel="nofollow noreferrer">http://docs.mongodb.org/manual/reference/operator/aggregation/min/</a>
  <a href="http://docs.mongodb.org/manual/reference/operator/aggregation/max/" rel="nofollow noreferrer">http://docs.mongodb.org/manual/reference/operator/aggregation/max/</a></p>
  
  <p>Question)</p>
  
  <ol>
  <li>Can I run this in one query with aggregate, maybe with <code>$project</code></li>
  <li>Is there another method than <code>aggregate</code> that works without
  grouping </li>
  <li>Will 1)/2) be more time efficient than the first solution with sorting?</li>
  </ol>
  
  <p>EDIT:
  Solved with the first solution, but I think there is a more efficient solution because this needs two database operations:</p>
  
  <pre><code>    async.parallel
        min: (next) -&gt;
          ImplantModel.findOne(newFilter).sort("serialNr").exec((err, result) -&gt;
            return next err if err?
            return next null, 0 if !result?
            next(null, result.serialNr)
          )
        max: (next) -&gt;
          ImplantModel.findOne(newFilter).sort("-serialNr").exec((err, result) -&gt;
            return next err if err?
            return next null, 0 if !result?
            next(null, result.serialNr)
          )
        (err, results) -&gt;
          console.log results.min, ' ', results.max
          return callback(err) if err?
          return callback null, {min:results.min, max:results.max}
    )
  </code></pre>