title: Sorting and Mongoose.js findOneAndRemove
body: <p>According to the Mongoose.js docs, it should be possible to add a sort directive to methods passed directly to the database like <code>findOneAndUpdate</code> or <code>findOneAndRemove</code>.</p>
  
  <p>I'm trying to grab a single document that matches a criterion and remove it from the database. So far, I have tried:</p>
  
  <pre><code>Model.findOneAndRemove({foo: 'bar'})
      .sort({created_at: 'asc'})
      .exec(callback);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Model.findOneAndRemove({foo: 'bar'}, {sort: {created_at: 'asc'}}).exec(callback);
  </code></pre>
  
  <p>Both of which seem to ignore the sort instruction and simply find and remove the most recently added matching document, not the document with the earliest <code>created_at</code> date. </p>
  
  <p>Issuing the query as a <code>findOne</code> and then removing the document in the callback function works as expected, e.g.,</p>
  
  <pre><code>Model.findOne({foo: 'bar'}).sort({created_at: 'asc'})
      .exec(function (err, doc) { 
          doc.remove(); 
      });
  </code></pre>
  
  <p>returns and removes the document with the earliest <code>created_at</code> date, so I believe that sorting in <code>findOneAndRemove</code> queries (which, unlike regular queries, are handed directly to MongoDB) must use a different syntax.</p>
  
  <p>Using <code>findOne</code> instead of <code>findOneAndRemove</code> is a viable option, but I would prefer that the operation be atomic if at all possible.</p>
  
  <p>Is it possible to use sort directives with Mongoose.js queries like <code>findOneAndUpdate</code> or <code>findOneAndRemove</code>, and, if so, what syntax is used?</p>