title: How to make a parallel and sequential job queue (FIFO) from MongoDB collection?
body: <p>Here is my schema of the collection:</p>
  
  <pre><code>var mongoose = require('mongoose');
  
  var urlSchema = new mongoose.Schema({
    url:  String,
    easeDate: { type: Date, index: 1},
    created: { type: Date, default: Date.now }
  });
  </code></pre>
  
  <p>I need to do an update action with the oldest document (by easeDate) to change its <code>easeDate</code> date to «now + some timeout» and get the affected document. Is it possible in one request?</p>
  
  <p>Basically, I want to make something like a queue from the collection (the "oldest" one is the next one pulled out i.e. first in first out). Deletion of urls (documents in the collection) is done by other conditions. I don't want to delete from queue but put to the end of it by updating <code>easeDate</code>.</p>
  
  <p>Finally, I want to take the available url and set a timeout to it, so that the next time there was returned the next url. If it was the last url, then <code>null</code> is returned next time, because of timeout.</p>
  
  <p>And if I can update it so, how can I query the database (mongoose) to get the next url where easeDate &lt; Date.now()? Could you please give an example in JavaScript?</p>