大佬教程收集整理的这篇文章主要介绍了Node.js mongoose [RangeError:超过最大调用堆栈大小],大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我无法解决问题,因为大多数堆栈问题在其他的stackoverflow问题关于节点处理数百个回调,但我只有3在这里。
我的代码是:
app.post('/poker/tables/:id/join',function(req,res){ var id = req.params.id; models.Table.findById(id,function (err,tablE) { if(err) { console.log(err); res.send( { message: 'error' }); return; } if(table.players.length >= table.maxPlayers ) { res.send( { message: "error: Can't join ! the Table is full" }); return; } console.log('Table isnt Full'); var BuyIn = table.minBuyIn; if(req.user.money < table.maxPlayers ) { res.send( { message: "error: Can't join ! Tou have not enough money" }); return; } console.log('User has enought money'); modelS.User.update({_id:req.user._iD},{ $inc:{ money : -BuyIn }},function(err,numAffected) { if(err) { console.log(err); res.send( { message: 'error: Cant update your account' }); return; } console.log('User money updated'); table.players.push( {userId: req.user._id,username: req.user.username,chips:BuyIn,cards:{}} ); table.save(function (err) { if(err) { console.log(err); res.send( { message: 'error' });return; } console.log('Table successfully saved with new player!'); res.send( { message: 'success',table: tablE}); }); }); })});
在最后的保存操作中发生错误!
我使用MongoDB与mongoose所以’表’和’用户’是我的数据库集合。
这是从我的第一个项目,nodejs,expressjs和mongodb,所以我可能在异步代码中犯了很大的错误:(
编辑:我试图用更新替换保存:
@H_131_14@models.Table.update({_id: table._iD},{ '$push': { players : {userId: req.user._id,cards:{}} } },numAffected) { if(err) { console.log(err); res.send( { message: 'error' });return; } console.log('Table successfully saved with new player!'); res.send( { message: 'success',table: tablE}); });
但是它不会帮助错误仍然来临,我不知道如何调试它:
例如:
@H_131_14@model.find().where( "property",OtherModelInstance );
这将触发该错误。
@H_131_14@model.find().where( "property",OtherModelInstance._id ); // or Model.find().where( "property",OtherModelInstance.toObject() );
这可能会阻止你现在的问题。
他们的GitHub回购中有一个问题,我报告了这一点,但是现在没有修复。 See the issue here。
以上是大佬教程为你收集整理的Node.js mongoose [RangeError:超过最大调用堆栈大小]全部内容,希望文章能够帮你解决Node.js mongoose [RangeError:超过最大调用堆栈大小]所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。