我正在为我的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)
{})
试试这个:
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)
{})
注意:你不应该留下很长的代码行,它们很难通读