Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Mongoid查询';s等算子_Ruby On Rails_Ruby_Mongoid - Fatal编程技术网

Ruby on rails Mongoid查询';s等算子

Ruby on rails Mongoid查询';s等算子,ruby-on-rails,ruby,mongoid,Ruby On Rails,Ruby,Mongoid,我想得到我数据库中的第一个42岁的人 如何使此查询生效: Person.where(:Age.eq => 42).first 我没有得到查询结果,而是得到: undefined method `eq' for :Age:Symbol 那么,仅仅: Person.where(Age: 42).first ?那么: Person.where(Age: 42).first ?试试看:- Person.where(:age => 42).first 它将查询年龄为42岁的人 或 以

我想得到我数据库中的第一个42岁的人

如何使此查询生效:

Person.where(:Age.eq => 42).first
我没有得到查询结果,而是得到:

undefined method `eq' for :Age:Symbol
那么,仅仅:

Person.where(Age: 42).first

那么:

Person.where(Age: 42).first
?试试看:-

Person.where(:age => 42).first
它将查询年龄为42岁的

以这种方式查询:-

Person.find_by age: 42
find_by方法查找与此条件匹配的第一条记录

试试看:-

Person.where(:age => 42).first
它将查询年龄为42岁的

以这种方式查询:-

Person.find_by age: 42
find_by方法查找与此条件匹配的第一条记录


Person.where(年龄:42)。首先如果不存在,则尝试创建并返回:Person.where(年龄:42)。首先\u或\u createPerson.where(年龄:42)。首先如果不存在,则尝试创建并返回:Person.where(年龄:42)。首先\u或\u创建