0
I know that this mistake may have several causes, but I have not been able to know mine. I have a function to save a Document in my Mongodb and I am using callback for this. The code is executed until saving the new document, after that I have an error. The code and the following:
function saveUser(userName, socialMediaType, socialMediaID, setDocNumber, callback){
var user;
if(socialMediaType == "fbUID"){
user = new users({
userName: userName,
userEmail: 'userEmail',
teams:[],
fbUID : socialMediaID
});
}else
if(socialMediaType =="google"){
//do the same
}
var query = {}
query["'"+ socialMediaType +"'" ] = socialMediaID
users.findOne(query, function(err, userFound){
if (err) { // err in query
log.d("Error in query FoundUser", err)
log.d("User Found", userFound)
}else
if(userFound == undefined){ //if user does not exist
user.save(function(err, user){
if(err) return console.error(err);
log.d("user saved", user);
currentSession = sessionOBJ.login(user._id, socialMediaID);
callback(currentSession,"created")
});
}else{
currentSession = sessionOBJ.login(userFound._id, socialMediaID);
callback(currentSession,"logged")
}
});
}
I call the function through the function below:
f(fbUID !== undefined){
userModelOBJ.saveUser(userName,"fbUID", fbUID, function(currentSession, status) {
res.send({"status":status,
"sessionID": currentSession.sessionID,
"expires" : currentSession.date});
});
But I continue with the following error:
The error is in the following line :
callback(currentSession,"created")
Can someone help me with that?
I’ve done a lot of research but I can’t find an answer.
Wow, I falter. Thank you so much for your answer. I just chose the second one because I found it more complete.:)
– debeka
We usually focus on function, where we made a mistake and didn’t even notice her call.
– melkysalem