我使用collction.find()
从Mongodb数据库调用一个对象,我将结果分配给一个名为EX1
的变量
这是响应,这是正确的:
{
"_id": {
"$oid": "5a351a5f5bd22b09ac494fa1"
},
"OrigName": "feras",}
现在,如果我想在浏览器中显示OrigName
并尝试使用EX1.OrigName
访问该值,我会得到"值未定义"。那是为什么?
这是完整的代码:
var Nameh = req.body.Name.toLowerCase();
var Numberh = req.body.Number;
cell.find({OrigName : Nameh , CellNumber : Numberh }, function(err, cells){
if (err) {
console.log("Error occured");
}
else{
cello = cells;
console.log(Cello.OrigName);
if (cello.length > 0) {
var Name1 = cello.NameofDonor + " " + cello.Name2ofDonor;
var Name2 = cello.NameofPatient;
var Type = cello.Type;
var Age = cello.Age;
var Problem = cello.Problem;
res.render("result", {Name1 : Name1 , Name2: Name2 , Type: Type, Age : Age, Problem : Problem});
}
else{
res.send("Nothing Found !");
}
}
});
这是架构:
var CellPattern = new mongoose.Schema({
CellNumber: Number,
OrigName: String,
NameofDonor: String,
Name2ofDonor: String,
Type: String,
NumberofDonor: Number,
NameofPatient: String,
Problem: String,
Age: Number,
});