首页 > 解决方案 > 猫鼬选择错误

问题描述

我有一个像这样的猫鼬模式

    first_name          : String,
    other_names         : String,
    last_name           : String,
    gender              : String,
    title               : String,
employment      :{
        office              : String,
        location            : String
    },
    hobbies         :[{
        hobbied_id          : Schema.Types.ObjectId
    }],
    contact     :[{
        address             : String,
        city                : String
    }]

当我尝试通过我使用的 mongoose 从 mongodb 中提取信息时

Person.find({'exployment.office':'Greenway'})
    .exec(function(err, result){
        console.log(result);//<- this gives expected result 
        console.log(result.employment.office);//<- this produces error of undefined
        console.log(result.contact.address);//<- this produces error
    });

这会产生与在 Greenway 工作的所有人员有关的所有信息。但是当我尝试从结果中获取特定细节时,它会产生未定义的错误,请问我做错了什么,还有任何书籍或网站对学习猫鼬有用

标签: mongoose

解决方案


推荐阅读