我可以看到在控制檯中填充值,但在嘗試訪問它時,我得到undefined
:貓鼬:不能訪問填充值
const AccountProfile = new Schema({
owner: { type: String },
firstName: { type: String },
lastName: { type: String },
countryId: { type: mongoose.Schema.Types.ObjectId, ref: "Country" }
});
const Country = new Schema({
name: String
});
AccountProfile.statics.getProfile = function (username, cb) {
this.model("AccountProfile").findOne({owner: username})
.populate("countryId")
.exec(function (err, profile) {
if (err) {
return cb(err);
}
console.log(profile.countryId);
return cb(null, profile);
});
};
輸出的格式如下: { _id: 57a9d5cda3c91dda14eb50f0, Name: 'UK' }
打印profile.countryId._id
看起來不錯,但是profile.countryId.Name
是undefined
!
任何線索?使用貓鼬4.6.6版
檢查是否有在關鍵 – chridam
任何空格能否請您顯示,目前我國的架構? –
@chridam這似乎不是問題所在。 'JSON.stringify(profile.countryId)的輸出''是{ 「_id」: 「57a9d5cda3c91dda14eb50f0」, 「姓名」: 「英國」}' – ierax