[英]Where does the "err" argument come from in Mongoose?
不确定这是否是比 Mongoose 本身更一般的 JS 问题,但是在下面的代码中提供“err”参数的函数是什么?
//Save a new cat called "Thomas" to the "Cats" collection Thomas.save( function(err, cat) { if (err){ console.log("Cat not saved") } else { console.log("Saved") } })
什么都异步操作u的进行save()
或findByName()
...等,当u使用回调,传统上的第一个参数callback
是error
值。 如果函数遇到error
,那么它们通常会调用callback
,第一个参数是一个Error
对象。
如果它干净地退出,那么他们将调用callback
,第一个参数为空,其余为返回值。
asyncOperation ( params.., function ( err, returnValues.. ) {
//This code gets run after the async operation gets run
});
在您的情况下, .save()
给出 err if hits an error
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.