Reputation: 2655
i have a problem to save data to database,when i post the data, its only saves _id and _v only
.here my api
const createPatient = (req, res, next) => {
const patient = new Patient();
name = req.body.name;
email = req.body.email;
hashed_password = req.body.hashed_password;
ID = req.body.ID;
address = req.body.address;
KK_number = req.body.KK_number;
occupation = req.body.occupation;
photo = req.body.photo;
patient.save( (err, result) => {
if (err) {
return res.status(400).json({
error: err,
});
}
console.log(patient);
res.status(200).json({
message: 'Successfully signed up!',
});
console.log(result);
});
};
anyone know whats wrong with my code?
Upvotes: 1
Views: 1401
Reputation: 2867
The problem with your code is that you are not creating the patient object. While you are creating variables to hold the patient details, you are not adding them to the patient object.
This should work.
const createPatient = (req, res, next) => {
const patient = new Patient({
name : req.body.name;
email : req.body.email;
hashed_password : req.body.hashed_password;
ID : req.body.ID;
address : req.body.address;
KK_number : req.body.KK_number;
occupation : req.body.occupation;
photo : req.body.photo;
});
patient.save( (err, result) => {
if (err) {
return res.status(400).json({
error: err,
});
}
console.log(patient);
res.status(200).json({
message: 'Successfully signed up!',
});
console.log(result);
});
};
Upvotes: 1