var wordsSchema = new mongoose.Schema({
words: [{
w_id: Schema.Types.ObjectId,
name: String,
meaning: String,
synonyms: String,
sentence: String
}]
})
var knownWordsSchema = new Schema({
kWords:[{
type: Schema.Types.ObjectId,
ref: "Words"
}]
})
How do i populate KnownWords, as the objectId i need to populate it is inside and array of object
例如:如果knownWords的id为"a"且单词为 words: [{ w_id: a, name: "h", meaning: "h", synonyms: "h", sentence: "h" }]
我希望knownWords有一个对象为 { name: "h", meaning: "h", synonyms: "h", sentence: "h" }
** P.s:我是一名初学者,所以我不知道该怎么说 . **
1 回答
KnownWordSchema格式不正确 .
现在代码中的某个地方:
populate方法将填充指定的字段 .