Let's say I have the following documents
{colors: [red, blue, green]}
{colors: [yellow, brown, green]}
{colors: [purple]}
{colors: [red, blue, orange]}
I want to make a function that queries the collection for documents that have at least one of the colors in the input, which is an array. So for example, if I want to find a document with red, blue, and/or green, I would write
findColors([red, blue, green])
and it would return
{colors: [red, blue, green]}
{colors: [red, blue, orange]}
{colors: [yellow, brown, green]}
IN THE ABOVE ORDER, as the document with the most perfect match is first, and the least perfect match is last. My problem is that the number of elements in the array are arbitrary, so I don't know how to combine them into one query without a loop. The problem with just passing the array in directly is that it will only return
{colors: [red, blue, green]}
but I want as many matches as possible. Plus, order within the array shouldn't have to matter.
Is there a way to either 1) combine multiple independent queries into one big query 2) use some sort of pattern matching function on the array such that it creates every possible combination of the elements of the array, which I can then pass into the function.
Also, in order to keep the run time low, I'm thinking of just writing "Stop running after you find 10 documents"