“mongoose”的说法在哪里来自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") } })
什么是asynchronous操作你正在执行save()
或findByName()
..等,当你使用callback,传统的callback的第一个参数是error
值。 如果函数遇到error
,那么他们通常会调用第一个参数为Error
对象的callback
函数。
如果它干净地退出,那么它们将调用第一个参数为空的callback
,其余的是返回值。
asyncOperation ( params.., function ( err, returnValues.. ) { //This code gets run after the async operation gets run });
在你的情况.save()
给出错误,如果命中error
。