开发者_如何学Python\"books\" />
开发者

mongoid embedded documents

开发者 https://www.devze.com 2023-03-03 07:07 出处:网络
i have some embedded documents. Company -> Stand -> Product. Document product have field \"tag\". I can do this request very well: Company.where(\"stands.products.tags\" => 开发者_如何学Python\"books\

i have some embedded documents. Company -> Stand -> Product. Document product have field "tag". I can do this request very well: Company.where("stands.products.tags" => 开发者_如何学Python"books") but i want to find with two tag names, for example,

Company.where("stands.products.tags" => "books").where("stands.products.tags" => "toys"), but in this example mongo will find only "toys tags". How i can find more tags in one request?


I suggest you refactor your tags attribute into an array of strings, index them and then have a look at this helpful method

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号