2016-11-23 93 views
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

+1

IDK的,但有路徑'「kategoriChildren」額外空間' –

+0

您確實將您的架構創建爲'Kotegori',並將您的鏈接創建爲'Kategori' –

+1

@GrégoryNEUTthanx man。 – Lupus

回答

1

,以便在評論部分說:

有在populate(...)描述' kategoriChildren'的空間。

和類別架構得到了一個拼錯名字:

你沒有創建您的架構爲Kotegori和駕駛員學校你的鏈接

+1

我剛剛浪費了我的3天,並且看不到那麼小的空間:S:S這不是我的代碼。我只是在審查這個,我想我會殺死一個人。 – Lupus