title: MongoDB aggregation result difference
body: <p>I'm trying to compose a query to find all documents in a collection with the 'date' &lt; current date, flag = true, sort by date (descending) and limit the result to (e.g.) 10 documents, then select all the <strong>remaining</strong> documents (satisfying the date and flag conditions) in the collection for an update to be performed. SQL equivalent would be:</p>
  
  <pre><code>SELECT * FROM TABLE
  WHERE DATE &lt; SYSDATE
  AND FLAG = TRUE
  MINUS
  SELECT * FROM TABLE
  WHERE DATE &lt; SYSDATE
  AND FLAG = TRUE
  ORDER BY DATE DESC
  LIMIT 10
  </code></pre>
  
  <p>So far I have:</p>
  
  <pre><code>db.scratch.aggregate(
    [
      { $match: { flag: true, date: { $lt: new Date() } } },
      { $sort: { date: -1 } },
      { $limit: 10 }
    ]
  )
  </code></pre>
  
  <p>Is it possible to make the subtraction in the DB, or the only option I have is to process the results of two queries on the client side?</p>