How can I (using Node.js and MongoDB through Mongoose) search for an many items in an array in document.
For example, if I have documents like:
{
_id: 123, field1: 'abc', field2: ['def', 'ghi', 'jkl'],
_id: 456, filed1: 'abc', filed2: ['jkl', 'ghi', 'def']
}
And the schema is called schema1, how can I perform a search with a query like
{field1: 'abc', field2: ['def', 'jkl']}
and get both documents (all documents whose field1 = 'abc' and field2 contains both 2 items in the array in query)?
I tried using schema1.find() but it only matches the arrays as a whole not their items. So none of these 2 documents would return.