我在猫鼬中有这样的自我参考:
var wordSchema = new mongoose.Schema({
content : String,
country: [{type: mongoose.Schema.Types.ObjectId, ref: 'Country'}],
trad: {
words: [{
_id: { type: mongoose.Schema.Types.ObjectId, ref: 'Word' }
}]
}
});
我想用 find 取回我的模型的属性内容:
Word.find({ content:regex, country:'5464dcee1874048e2c623389' }).populate('trad.words').exec(function (err, words) {
if (!err) {
res.json(words);
} else {
console.log(err);
}
});
这是我得到的结果:
_id: "5468d91c6481cd063033a4d0"
content: "content"
country: [5464ddd226e63fad2c5aa053]
trad: {words:[{_id:5468d91c6481cd063033a4cf}]}
words: [{_id:5468d91c6481cd063033a4cf}]
0: {_id:5468d91c6481cd063033a4cf}
_id: "5468d91c6481cd063033a4cf"
我不明白为什么它没有在 subDocument 字中返回我的其他属性。你能帮我理解我做错了什么吗?
谢谢,
马克西姆