Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
mongoose find document with array that has a value BUT it checks like a wild card

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!