Created
February 7, 2010 12:14
-
-
Save seban/297400 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MongoMapper | |
module FindRandom | |
def self.included(document) | |
document.extend ClassMethods | |
end | |
module ClassMethods | |
# Fetch random document from MongoDb | |
def find_random(conditions = {}) | |
options = {} | |
options[:conditions] = conditions | |
options[:skip] = rand(self.collection.count) | |
self.find(:first, options) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment