[英]mongoid, query with element in array
I have structure class like this: 我有这样的结构类:
#<Transaction _id: 54d46d6a6e6f626fbcc70000, _keywords: ["1", "test1", "test2", "abc1", "projectmongo", "last2", "taka"]>
array keyword map with: [field1, field2,...] So I want to query to get all transaction have field1 == "1" Is this possible? 数组关键字映射具有:[field1,field2,...]因此,我想查询所有事务都具有field1 ==“ 1”这可能吗?
MongoDB "dot notation" . MongoDB “点表示法” 。 Don't expect there to be a "rails like" SQL ORM mapping equivalent when using functionality like arrays which are generally not supported for those storage engines:
使用数组等功能(通常不支持这些存储引擎)时,不要指望有类似“ ORMS”的SQL ORM映射:
Class.collection.find({ "_keywords.0" => "1" })
So the Moped syntax here is more raw to the MongoDB functionality. 因此,此处的Moped语法对MongoDB功能而言更为原始。
That basically says "look at the first array element to see if it matches the value I ask for". 基本上就是说“查看第一个数组元素,看它是否与我要的值匹配”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.