我正在填充一个字符数组,每个字符都有它的类和种族作为对象的引用。什么是正确的填充查询来获得,种族和类。谢谢您的回答
UserModel.
findOne({ Something: 'Something' })
populate({
path: "characters",
populate:{
path: "class, race"
}
})
.exec(function(err, docs) {
console.log(docs.characters[1]);
console.log(err);
});
- 改变了模型的结尾,现在它可以工作了。
UserModel.
findOne({ Something: 'Something' })
.populate({
path: "characters",
model: 'Characters',
populate: [{
path: 'class',
model: 'Classes'
},
{
path: 'race',
model: 'Races'
}]
})
.exec(function (err, docs) {
console.log(docs.characters[1]);
console.log(err);
});
试试这个 :
UserModel.
findOne({ Something: 'Something' })
.populate({
path: "characters",
model: 'Character',
populate: [{
path: 'class',
model: 'Class'
},
{
path: 'race',
model: 'Race'
}]
})
.exec(function (err, docs) {
console.log(docs.characters[1]);
console.log(err);
});