我可以看到在控制台中填充值,但在尝试访问它时,我得到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