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

81
Views
Tratando de hacer una función de emparejamiento

Así que estoy tratando de encontrar un oponente para el usuario en función de sus trofeos, funciona bien cuando la condición no se ejecuta, pero cuando se ejecuta la condición, se ejecuta en un bucle infinito.

 const UserProfile = require("../schemas/userProfile") async function matchmake(user, message) { let UserProfileDetails = await UserProfile.findOne({ userID: user.id }); let userTrophies = UserProfileDetails.trophies; let userMatched = await UserProfile.aggregate([ { $match: { trophies: { $gte: userTrophies - 10, $lte: userTrophies + 10 } } }, { $sample: { size: 1 } } ]); let otherUserID = userMatched[0].userID; console.log("userID -"+otherUserID); if (otherUserID === user.id) { otherUserID = await matchmake(user, message); } return otherUserID; } module.exports = { matchmake }```
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Si se trata de un bucle infinito, parece que su agregación sigue atrayendo al mismo usuario como 'user.id', que recursivamente llama a la función de emparejamiento una y otra vez.

Intentaría agregar una condición $not a su coincidencia que verifique el user.id. De esa forma, la agregación no devuelve el usuario original.

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!