i am sure this question is asked before but i was not able to find the right answer.
I have this user model schema and i want to save it into my mongo db. The saving process it works just fine but i can't return the user data afterwards.
I think the whole problem where i get confused is the function with in the save method which handles this callback.
Let me show you my code:
var saveUser = user.save(function(err, arg){
if (err) {
console.log(err);
return err; // in case of error
}
return arg; // the user object i want to assign to the saveUser variable
});
//the setTimeout to make sure the callback is finished
setTimeout(function(){
console.log(saveUser); // the return (should have data at this moment)
}, 1000);
Thanks in advance.