2017-10-13 54 views
0

谁知道是什么where(:genres.in => [ "rock" ]意味着mongoid
我看到文件这些代码:??什么地方(:genres.in => [“石头”]意味着Mongoid,我怎么能找到参考

class Band 
    include Mongoid::Document 
    field :country, type: String 
    field :genres, type: Array 

    scope :english, ->{ where(country: "England") } 
    scope :rock, ->{ where(:genres.in => [ "rock" ]) } 
end 

https://docs.mongodb.com/mongoid/master/tutorials/mongoid-queries/#named-scopes

似乎就意味着找到在哪里风格包含“石头”的文件,但我不知道,因为我无法找到一个参考解释in

回答

0

这是一个小红宝石DS L,它几乎可以直接映射到mongodb查询操作符。也就是说,这个红宝石行:

Band.where(:genres.in => [ "rock" ]) 

将转化为这MongoDB的查询(在这里使用shell语法)

db.bands.find({ genres: { $in: ['rock']}}) 

同为age.gt,等这里的底层mongodb的查询操作的列表:https://docs.mongodb.com/manual/reference/operator/query/#query-selectors