如何在猫鼬中为深度人口查询选择字段
How to have selective field for deep population query in mongoose
我的查询如下图:
orderSubInfo.find({
'order_id': {
$in: orderArray
}
}).populate({
path: 'order_id',
populate: {
path: 'foodtruck_id',
model: 'foodtruck'
}
}).exec().then((info) => {
res.json({
status: '200',
message: 'Your OTP',
data: info
})
}).catch((err) => {
res.json({
status: '500',
message: 'Oops,something went wromg'
})
});
现在发生的事情发生在 populate {path:foodtruck_id,model:'foodtruck}
之后。我得到了不必要的字段。但我只想 foodtruck_name,foodtruck_location
。那么我应该如何修改我的查询?
Select 仅您要包含的字段 (mongoose population):
populate: {
path: 'foodtruck_id',
model: 'foodtruck',
select: 'foodtruck_name foodtruck_location' //to exclude _id add -_id
}
我的查询如下图:
orderSubInfo.find({
'order_id': {
$in: orderArray
}
}).populate({
path: 'order_id',
populate: {
path: 'foodtruck_id',
model: 'foodtruck'
}
}).exec().then((info) => {
res.json({
status: '200',
message: 'Your OTP',
data: info
})
}).catch((err) => {
res.json({
status: '500',
message: 'Oops,something went wromg'
})
});
现在发生的事情发生在 populate {path:foodtruck_id,model:'foodtruck}
之后。我得到了不必要的字段。但我只想 foodtruck_name,foodtruck_location
。那么我应该如何修改我的查询?
Select 仅您要包含的字段 (mongoose population):
populate: {
path: 'foodtruck_id',
model: 'foodtruck',
select: 'foodtruck_name foodtruck_location' //to exclude _id add -_id
}