【发布时间】:2021-11-07 23:08:51
【问题描述】:
function shield() {
setInterval(async function () {
const ProfileModelS = require("../models/ProfileSchema");
await ProfileModelS.find({}).then((doc) => {
doc.forEach(async (u) => {
if (u.ShieldPoints <= 0) return console.log(u.Name);
if (u.ShieldPoints > 0) {
await ProfileModelS.findOneAndUpdate(
{ userID: u.userID },
{
$inc: {
ShieldPoints: -1,
},
},
console.log("done")
);
}
});
});
}, 1000);
}
module.exports = shield
我希望我的 mongodb 在每个 Interval 上获取模型,但它没有这样做,每当我运行我的代码时它会获取模型,例如,它会获取 [{name: 'Joseph' , Points: 10}, {name: 'carman' , Points: -1}, {name: 'thee' , Points: 2}] 根据代码,它不会适当地减少点小于0的对象的点, 但它会继续减少超过0的对象点,如果对象点达到0,我希望它停止减少点,它应该继续减少点大于0的对象的点
简而言之,一旦特定对象的点达到 0,就应该停止该过程
【问题讨论】:
-
将第二个 if 更改为 else 并尝试
标签: database mongodb discord discord.js bots