data in mongodb:
{
_id: 123,
names: ["john", "sam"]
}
{
_id: 321,
names: ["peter"]
}
my code:
// "Model" is the mongoose model
const Query = ["john", "peter"]
const matchedNames = await Model.find({ names: {$in: Query} })
console.log(matchedNames)
// returns:
// {_id: 123,names: ["john", "sam"]}
// {_id: 321,names: ["peter"]}
// BUT if my query is like this:
const Query = ["o", "e"]
const matchedNames = await Model.find({ names: {$in: Query} })
console.log(matchedNames)
// returns nothing
i dont know how to explain this but basically i want it to return
{_id: 123,names: ["john", "sam"]}
{_id: 321,names: ["peter"]}
if my query is
const Query = ["o", "e"]
Basically I want it to return all documents which names's value includes a string that has the letter o or e in it