Mongoid nested array query

问题内容:

I have to query a mongoid array for value combinations inside the array.

The query array example looks like this:

qa = [["a","b","c"], ["a","b"],["b","c"]]
Model.any_in(:field => qa)

What I need in return is all models in which the :field contains the values(but maybe also other ones)
For example it should return Models where :field is ["b",'c','d'] too because of ["b","c"] in the query.

ATM my solution is to iterate over the query array and doing any_in for every nested array, then combining results. This worked of course, but now if have the situation of a vastly increased query array, like about 20k “subarrays”. This takes way too much time.
So far i tried combinations of any_in and any_of, all which only led me to a solution where I can query an exact match of the nested arrays, like models with ["a","b","c"] in the :field

问题评论:

    
For blocks of code, just indent with four spaces or use the {} button.

原文地址:

https://stackoverflow.com/questions/47755362/mongoid-nested-array-query

添加评论