title: MongoDB collections as FIFO stack
body: <p>I need to implement the FIFO logic with MongoDB collection:</p>
  
  <ol>
  <li>Pop the first document from MongoDB collection.</li>
  <li>Push the document to MongoDB collection and place it as a last document.</li>
  </ol>
  
  <p>The documents in collection do not have any indexes except auto-generated _id (ObjectId).</p>
  
  <p>I wonder, is it possible to findAndRemove the first document from collection and to guarantee that push and pop operations will perform as FIFO stack atomically?</p>
  
  <p>I know that it is possible to do with an array inside document with atomic push and pop operations, but the main problem is that if I will store all my data inside 1 document's array, it's size will exceed 16MB (the maximum allowed size of MongoDB document)</p>
  
  <p>Thanks in advance,
  Valentin</p>