Node.js RangeError:无效状态代码:未定义[Node+;mongoDB]
当我尝试使用我在模式中定义的方法时,会出现这个错误。错误发生在我发出POST请求时 这是我在模式中使用的静态方法:Node.js RangeError:无效状态代码:未定义[Node+;mongoDB],node.js,mongodb,express,mongoose,Node.js,Mongodb,Express,Mongoose,当我尝试使用我在模式中定义的方法时,会出现这个错误。错误发生在我发出POST请求时 这是我在模式中使用的静态方法: usuarioSchema.static.checkIfUserExists = function(email,cb){ const query = Usuario.findOne({email}); return query.exec(cb); } 我从我的路由器这样调用它: Usuario.checkIfUserExists(email, (err, exis
usuarioSchema.static.checkIfUserExists = function(email,cb){
const query = Usuario.findOne({email});
return query.exec(cb);
}
我从我的路由器这样调用它:
Usuario.checkIfUserExists(email, (err, exists)=>{
if(err){
next(err);
}
if(exists){
res.json(new CustomError('DuplicatedEmail','Ya existe un usuario registrado con ese email',res));
return;
}
}
我试图使用调试器,但它没有进入函数。使用console记录调用执行之前的内容,但是从de schema静态函数内部无法记录任何内容
使用try catch时,它会给我一个错误,即checkIfUserExists不是一个函数OMG,它是静态的,不是静态的
我的90分钟都浪费在这上面了。天哪,这是静态的,不是静态的
我90分钟的生命都浪费在这上面了。这是
静态
不是静态
。这是静态
不是静态
。我们都去过那里+1.为了微笑。需要它!:)我们都去过那里+1.为了微笑。需要它!:)