我正在为我的nodejs应用程序使用mongoose,我想填充到3的深度
服务有汽车,汽车有型号,型号有品牌
Service.find({removed:false,client:req.client_id})
.populate({path:'car',model:"ClientCar",populate:{path:"model",model:"Model"}})
.exec(function(err,services)
{})
在第二次填充中添加品牌时失败
Service.find({removed:false,client:req.client_id})
.populate({path:'car',model:"ClientCar",populate:{path:"model",model:"Model",populate{path:"brand",model:"Brand"}})
.exec(function(err,services)
{})
答案 0 :(得分:2)
试试这个:
Service.find({removed:false,
client:req.client_id})
.populate({
path:'car',
model:"ClientCar",
populate:[{
path:"model",
model:"Model"
},
{
path: "model.brand",
model:"Brand"
}]
)
.exec(function(err,services)
{});
要清楚,我的意思是尝试这个,因为它更整洁。我相当肯定唯一阻止你的代码正常工作的是缺失:在第三个填充之后
Service.find({removed:false,client:req.client_id})
.populate({path:'car',model:"ClientCar",populate:{path:"model",model:"Model",
populate{path:"brand", //here, should be populate: {}, not populate{}
model:"Brand"}})
.exec(function(err,services)
{})
注意:您不应该留下长时间的代码行,而且它们很难通读