Я хочу сохранить значения из документа mongoDB, чтобы вернуть их в качестве ответа.Код выглядит так:
exports.UserDiseaseInfo = (req, res, next) => {
let retval = {};
let dId = "";
let subDName = "";
let body = req.body;
let UId = (body.UId != undefined) ? body.UId : false;
let SubDId = (body.SubDId != undefined) ? body.SubDId : false;
if (UId == false || SubDId == false) {
res.status(404).send({
response: "Fail",
body: req.body
});
}
subDisease_model.findById(SubDId, function(error, doc) {
dId = doc['DiseaseID'];
subDName = doc['SubDisease'];
});
let data = {
response: 'success',
subDisease: subDName,
DiseaseId: dId
}
res.status(200).send(data);
};
However the output is:
{
"response": "success",
"subDisease": "",
"DiseaseId": ""
}
В то время как он должен быть
{
"response": "success",
"subDisease": "Migraine",
"DiseaseId": "5ad0850efdcab0ab875c48a4"
}
Любой совет, что я пропускаю?