0

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"}, ]

Billjesh Baidya
  • 189
  • 1
  • 12

0 Answers0