2011-05-05 91 views
0

我有一些嵌入式文档。公司 - >展位 - >产品。文件产品有字段“标签”。我可以很好地做到这一点:Company.where(“stands.products.tags”=>“books”),但我想找到两个标签名称,例如,mongoid嵌入文档

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

+0

什么是标签?它是一个字符串还是数组字段? – 2011-05-05 16:56:00

+0

它是字符串字段,而不是数组 – maxfry 2011-05-05 17:32:24

回答

2

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

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