Query on Mongoid Hash Field Query on Mongoid Hash Field mongodb mongodb

Query on Mongoid Hash Field


Person.where('things.tv' => 'Samsung').first

This is where Mongoid and MongoDB really shine. Mongoid's Criteria methods (Person.where, Person.any_of, Person.excludes, etc.) will give you much more flexibility than the ActiveRecord-style finders (passing a :conditions hash to Person.find, Person.first, etc.)

Mongoid's site has some great documentation on how to use Criteria:

http://mongoid.org/en/mongoid/docs/querying.html