UnhandledPromiseRejectionWarning: TypeError: 无法读取未定义的属性“json”

时间:2021-06-07 20:40:16

标签: javascript mongodb async-await

函数可以在不返回任何 json 的情况下工作,但是我也想要,否则用户不知道是否有任何工作。我真的不知道为什么会发生这种情况,也找不到任何解决方法。

const recursive = async (match, user, req, res) => {

  const currentUser = user;

  for (const like of match.likes) {
    
    if ( currentUser._id.equals(like._id) ) {

      await User.findOneAndUpdate({ _id: currentUser._id }, { $push: { matches: match } })
  
      await User.findOneAndUpdate({ _id: match._id }, { $push: { matches: currentUser } })
      res.json({message: 'Its a match'}).end();
  
    } else {
      console.log('Untrue'); 
         
    };
  };
};

0 个答案:

没有答案