所以我有这个代码块:
socket.on('win-fight', (data) => {
var newTempFight = TempFight({
code: Math.floor(Math.random() * 10) + 1,
ended: 0
});
newTempFight.save();
TempFight.findOne({code: newTempFight.code}).then((fight) => {
if(fight.ended === 1) {
console.log('NO NO NO');
} else {
TempFight.updateOne({"code": fight.code}, {$set: {"ended": 1}}).then((finished) => {
console.log('fight ended');
});
我在做什么是当套接字被触发时,我正在创建newTempFight,然后尝试检查其值ended
是否等于1
。
但是我收到此错误:无法读取以null结尾的属性。
已解决:newTempFight ['code']-可行