MongoidFindBy
MongoidFindBy adds simple functions to mongoid documents to find documents by dynamic fields.
Install
gem 'mongoid_find_by'
Usage
class Person
include Mongoid::Document
include Mongoid::FindBy
field :name, :type => String
end
# returns a single document
Person.find_by_name('Thomas')
Person.find_first_by_name('Thomas')
Person.find_last_by_name('Thomas')
# returns a document collection
Person.find_all_by_name('Thomas')
# throws Mongoid::Errors::DocumentNotFound
# exception for non existent documents
Person.find_by_name!('Thomas)
Credits
Copyright (c) 2012-2013 Thomas Boerger Programmierung http://www.tbpro.de