Mongodb / Node.js:无法访问json文件中对象的值

时间:2017-12-16 13:58:24

标签: javascript json node.js mongodb

我使用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,
});

0 个答案:

没有答案