where(:genres.in => [ "rock" ] 在 Mongoid 中是什么意思,如何找到参考?
what does where(:genres.in => [ "rock" ] mean in Mongoid and how can I find the reference?
有人知道 where(:genres.in => [ "rock" ]
在 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
似乎这意味着找到包含 "rock" 流派的文档,但我不确定,因为我找不到解释 in
.
的参考
这是一个小型 ruby DSL,几乎可以直接映射到 mongodb 查询运算符。即,此 ruby 行:
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
有人知道 where(:genres.in => [ "rock" ]
在 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
似乎这意味着找到包含 "rock" 流派的文档,但我不确定,因为我找不到解释 in
.
这是一个小型 ruby DSL,几乎可以直接映射到 mongodb 查询运算符。即,此 ruby 行:
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