0
我收到此錯誤,但架構中沒有虛擬。圓形填充拋出無關錯誤
Error: If you are populating a virtual, you must set the localField and foreignField options
架構
let kategoriSchemaObject = {
//...
kategoriChildren: [{
type: Schema.Types.ObjectId,
ref: 'Kategori'
}],
//...
}
let kategoriSchema = new Schema(kategoriSchemaObject , {
timestamps: {
createdAt: 'created_at'
}
});
mongoose.model('Kotegori', kategoriSchema);
查詢
Categories.find({
kategoriUst: null,
})
.populate({
path: 'kategoriChildren',
options: {
limit: 8,
},
populate: {
path: ' kategoriChildren',
select: 'name',
options: {
limit: 6,
},
},
})
.exec()
.then((data) => {
//...
next();
})
.catch((err) => next(err));
如果我刪除第二填充它的工作原理預期。
我失去了一些東西在這裏?關於這一點,我也開了一個issue。
IDK的,但有路徑'「kategoriChildren」額外空間' –
您確實將您的架構創建爲'Kotegori',並將您的鏈接創建爲'Kategori' –
@GrégoryNEUTthanx man。 – Lupus