Skip to content

Instantly share code, notes, and snippets.

@leopd
Forked from srleo/gist:5688438
Created August 28, 2013 15:36
Show Gist options
  • Save leopd/6367453 to your computer and use it in GitHub Desktop.
Save leopd/6367453 to your computer and use it in GitHub Desktop.
function add_rand_field(collection) {
collection.find().forEach(function(data) {
collection.update({_id:data._id}, {
$set:{rand:Math.random()}
});
});
collection.ensureIndex({rand:1},{background:true})
}
add_rand_field(db.mycoll);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment