데이터베이스 (MongoBD)에 값을 유지하는 콜백 함수가있는 nodeJS 응용 프로그램을 사용하고 있습니다. 아래 콜백 함수 :콜백 함수가 작동하지 않습니다.
exports.add = function(student, cb) {
var collection = db.get().collection('students');
collection.insert(student, function(err) {
if (err) {
throw err;
}
console.log("Record added");
});
}
상기 콜백 함수는 아래와 같이 다른 fuction를 호출한다 :
router.post("/add", function(req,res){
var student = req.body;
Students.add(student, function(err) {
if (err) {
throw err;
}
var respOut = JSON.stringify({id:student.id});
console.log("respOut");
res.send(respOut);
});
});
콜백 함수가 상기 굵은 (Students.add) 부로부터 호출
. 현재 DB에 데이터를 유지할 수 있습니다. 콘솔에서 출력을 얻지 못했습니다. (콘솔의 출력은 ->console.log("respOut");
) 위의 코드에서 UI의 응답이 있습니다. 콜백 기능에 문제가 있습니까? 아니면 누락 되었습니까?
당신이 exports.add에서 CB (ERR)를 호출하지 않는, 그 이후에해야한다 또는 당신의 console.log ("Record added") 전에 – progysm