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

147
Views
findOne is gaving me the same result for different IDs

I have a list of different Ids , and I'm trying to find the products that have those Ids and push them in another array. The problem is that when I use findOne() return the same product for all Ids.

let  wishpro = ['632a5e5rtybdaafd23','65fdaartbdqip55'];
            
            for(let i = 0; i < wishpro.length ; i++) {
                let x = await product.findOne({id : wishpro[i]});
                console.log("x : " + x.id )
                wishProducts.push(x);
            }

almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

findOne() will return the first match that it finds. Instead, you can use find() with $in operator, and fetch all of the records with one query:

const wishpro = ['632a5e5rtybdaafd23','65fdaartbdqip55'];

const result = await product.find({ id: { $in: wishpro } });
almost 4 years ago · Santiago Trujillo 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!