title: How to atomically pop random element?
body: <p>Is there a way to atomically pop (remove and retrieve) a random element with MongoDB - like Redis's <a href="http://redis.io/commands/spop" rel="nofollow">SPOP</a>?</p>
  
  <p>I've read the <a href="http://cookbook.mongodb.org/patterns/random-attribute/" rel="nofollow">RandomAttribute tutorial</a> but now I need to make sure that the element is also removed when fetched, and this must be done atomically.</p>
  
  <p>I guess as an alternative I could push the data into an array field pre-sorted, but I'd really prefer to have it fetch a random record.</p>
  
  <p>Looking at <code>$pop</code>'s documentation, it seems it can't take arguments, so it either removes the first or the last element of an array.</p>