I am trying to save my mongoDB with mongoose.app.post function calls the saveLogInfo function. The problem in saveLogInfo function is the code till
consoel.log ("inside savae")
is runnig but after that I got an error that
string is not a function
callback in not getting called and show an error that "saving failed."
the schema is: var LoginInfoSchema=new Schema({
username:String,
password:String
});
app.post function:
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
}
});
}
please guide me what is the error in this function
It looks like the callback
parameter that is being passed in when you call the saveLogInfo
function is a string rather than a function. Could you post the code that is calling saveLogInfo
?
It is possible that when you call saveLogInfo
, you are passing in the name of a function as the callback
parameter, but are mistakenly wrapping it in quotes.