我创建了一个函数来返回“minHospitalization'来自以下函数的db.Response字段是' [{" minHospitalization":1}]'
我想将值返回为' 1'而不是以json格式返回值。我如何实现它?
var getHospitalStayDuration = function (req, res, callback) {
var treatmentName = req.query.procedurename
treatmentDescModel.aggregate([
{ "$match": { "isDisable": "N", "treatmentName": treatmentName } },
{ "$project": { "_id": 0, "minHospitalization": 1} }
], function (err, result) {
if (err) {
//do smthing
} else if (!result.length) {
//do something
}
else {
//result= [{"minHospitalization":1}]
//callback(JSON.parse(JSON.stringify(result)).minHospitalization);
callback(JSON.parse(JSON.stringify(result)))
//How to return 1 instead of result??
}
})
}
答案 0 :(得分:0)
您可以使用key
:
callback(result[0].minHospitalization)