MongoidFindBy
¶ ↑
MongoidFindBy adds simple functions to mongoid documents to find documents by dynamic fields.
Install¶ ↑
ruby gem 'mongoid_find_by'
Usage¶ ↑
“‘ruby class Person include Mongoid::Document include Mongoid::FindBy
field :name, :type => String end “‘
“‘ruby # 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 © 2012-2013 Thomas Boerger Programmierung www.tbpro.de