【发布时间】:2012-10-03 18:02:59
【问题描述】:
我正在尝试使用 mongoose.app.post 函数调用 saveLogInfo 函数来保存我的 mongoDB。 saveLogInfo 函数中的问题是代码直到
consoel.log(“内部 savae”)
正在运行,但之后我收到一个错误
字符串不是函数
回调未被调用并显示“保存失败”的错误。
架构是: var LoginInfoSchema=new Schema({
username:String,
password:String
});
app.post 函数:
var LoginInfo=db.model('LoginInfo',LoginInfoSchema);
function saveLogInfo (username , password ,callback){
console.log("saveLogInfo CALLED");
var receivedObj = new LoginInfo({
username:username ,
password:password
});
console.log(receivedObj);
receivedObj.save(function(err , data){
console.log("inside Save ");
if(err){
//res.send(err);
console.log(err);
}
else{
callback(); // the error is here
}
});
}
请指导我这个函数的错误是什么
【问题讨论】:
-
您对
saveLogInfo的调用和 LoginInfo 架构是什么样的? -
架构是 :var LoginInfoSchema=new Schema({ username:String, password:String }); var LoginInfo=db.model('LoginInfo',LoginInfoSchema);
-
@JohnnyHK .....感谢您尝试解决我的问题,但现在我已经解决了我的问题。感谢上帝,我的代码正在运行