Skip to content

Instantly share code, notes, and snippets.

@mjhea0
Forked from zakuni/random_document.js
Created December 9, 2013 18:44
Show Gist options
  • Select an option

  • Save mjhea0/7878127 to your computer and use it in GitHub Desktop.

Select an option

Save mjhea0/7878127 to your computer and use it in GitHub Desktop.
var count = db.collections.count()
var rand = function(){return Math.floor( Math.random() * count )}
db.collection.find().limit(-1).skip(rand()).next();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment