mongoid,查询数组中的元素
mongoid, query with element in array
我的结构 class 是这样的:
#<Transaction _id: 54d46d6a6e6f626fbcc70000, _keywords: ["1", "test1", "test2", "abc1", "projectmongo", "last2", "taka"]>
数组关键字映射:[field1, field2,...]
所以我想查询让所有交易都有 field1 == "1"
这可能吗?
MongoDB"dot notation"。当使用像数组这样的存储引擎通常不支持的功能时,不要指望会有 "rails like" SQL ORM 映射等价物:
Class.collection.find({ "_keywords.0" => "1" })
所以这里的 Moped 语法对 MongoDB 功能来说更原始。
基本上就是说 "look at the first array element to see if it matches the value I ask for"。
我的结构 class 是这样的:
#<Transaction _id: 54d46d6a6e6f626fbcc70000, _keywords: ["1", "test1", "test2", "abc1", "projectmongo", "last2", "taka"]>
数组关键字映射:[field1, field2,...] 所以我想查询让所有交易都有 field1 == "1" 这可能吗?
MongoDB"dot notation"。当使用像数组这样的存储引擎通常不支持的功能时,不要指望会有 "rails like" SQL ORM 映射等价物:
Class.collection.find({ "_keywords.0" => "1" })
所以这里的 Moped 语法对 MongoDB 功能来说更原始。
基本上就是说 "look at the first array element to see if it matches the value I ask for"。