Mongoid查询的等于运算符
问题描述:
我想让我的数据库中的第一个42岁的人。Mongoid查询的等于运算符
我怎样才能让这个查询的工作:
Person.where(:Age.eq => 42).first
非但没有查询结果的,我得到:
undefined method `eq' for :Age:Symbol
答
尝试: -
Person.where(:age => 42).first
它将查询Person
有age = 42
OR
查询这样: -
Person.find_by age: 42
的find_by方法找到的第一个与此条件匹配的记录
+0
It works Person.where(:age => 42).first thank's :) – user3146542
Person.where(年龄:42)。首先 – Aby
如果不存在则尝试这种因此它会创建并返回:Person.where(年龄:42).first_or_create – Aby