I have such documents in Mongo:
{
_id: 1,
cat: ['a', 'b, 'c', 'd', 'e']
},
{
_id: 2,
cat: ['f', 'g, 'h', 'i', 'j']
},
{
_id: 3,
cat: ['a', 'b, 'f', 'g', 'h']
},
{
_id: 4,
cat: ['i', 'j, 'c', 'd', 'e']
}
and I have to filter the documents that have at least n occurrences (let' say 3) of 'cat' in a set I have, i.e.:
['a', 'b', 'c', 'f']
So in this case only the documents with _id equal to 1 and 3 should be returned because both of them have at least 3 occurrences of the categories present in the requested array.
What is the best way to solve this problem? Should I relay on aggregation framework or is there any easy way to do without it?