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

125
Views
How do I match by two separate arrays of ids in MongoDB?

I have 2 arrays with different ids :

  1. bikesWithNoOrders [id , id1 , id2]
  2. filteredResult [id3 , id5]

How do I make a query that finds them all

I have this :

queryBuilder.find({ _id: { $in: bikesWithNoOrders } });

queryBuilder.find({ _id: { $in: filteredResult } });

But the second one overwrites the first one because they dont share the same ids I want something like this :

queryBuilder.find({ _id: { $in: filteredResult } }).or({ _id: { $in: bikesWithNoOrders } });
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can just marge these 2 arrays on server side, and query with merged array. You can do it with concat():

queryBuilder.find({ _id: { $in: bikesWithNoOrders.concat(filteredResult) } });
about 4 years ago · Juan Pablo Isaza Report

0

Hope this answer will work for you.!

queryBuilder.find({ _id: { $in: [...bikesWithNoOrders,...filteredResult] } });
about 4 years ago · Juan Pablo Isaza Report
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!