【发布时间】:2021-12-15 09:55:45
【问题描述】:
所以我试图根据他的奖杯为用户找到一个对手,当条件不运行时它工作正常,但当条件运行时,它运行无限循环
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 }```
【问题讨论】:
标签: javascript mongodb discord discord.js