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

124
Views
Mongodb find by array of ids in order

I am making a dating app where an algorithm returns an array of matching user's uuid by sorting it. So I want to find all the users by that array of uuid in order.

I tried doing this

//init algorithm
const algo = new Match(currentUser, users);
//calculate score
algo.calcScore();
//sort it
algo.sort();
//get array of uids of matching users
const matches = algo.matching_users;

//find users by that array of uid
const matching_users = await User
  .find({
    uid: {
      $in: matches
    }
  })
  .skip(total_items - items)
  .limit(items)
  .lean()
  .exec()

This returns the users but not in order. For example let array of uids be: ["c", "d", "a", "b"] the above query returns user objects in: [{...uid: "a"},{...uid: "b"},{...uid: "c"},{...uid: "d"}, ]

Expected output: [{...uid: "c"},{...uid: "d"},{...uid: "a"},{...uid: "b"}, ]

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!