mongoid嵌入式文档

时间:2011-05-05 13:54:40

标签: ruby mongoid mongodb

我有一些嵌入式文件。公司 - >支架 - >产品。文档产品具有字段“标记”。我可以很好地完成这个请求:Company.where(“stands.products.tags”=>“books”)但我想找到两个标签名称,例如,

Company.where(“stands.products.tags”=>“books”)。where(“stands.products.tags”=>“toys”),但在此示例中,mongo只会找到“玩具标签” ”。如何在一个请求中找到更多标签?

1 个答案:

答案 0 :(得分:2)

我建议您将tags属性重构为字符串数组,对其进行索引,然后查看this helpful method

Company.any_in("stands.products.tags" => ["books", "toys"])