我想根据Movie
数组tags
来查询以下Mongodb
对象
Movie.last.tags
=> [{"type"=>"Genre", "tags"=>["Comedy"]}, {"type"=>"score", "tags" => ["Excellent"]}]
Movie.where({'tags' => {'$elemMatch' => {'type' => "Genre", "tags" => "Comedy"}}})
我可以使用Comedy
标记查询所有条目,但我需要将搜索范围限制为tags
数组中{"type"=>"score", "tags" => ["Excellent"]}
答案 0 :(得分:0)
您找到了解决方案 @Veeram,请复制此答案并根据您的意愿进行修改。我会接受它,我将感谢你与我们分享你的专业知识
Movie.where({'tags' => { '$all' => [
{'$elemMatch' => {'type' => "Genre", "tags" => "Comedy"}},
{'$elemMatch' => {'type' => "score", "tags" => "Excellent"}}
]}
})
非常感谢 最好的祝福 的Fabrizio