我的查询如下所示:
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
。那我应该如何修改我的查询呢?
答案 0 :(得分:1)
仅选择要包含的字段(mongoose population):
populate: {
path: 'foodtruck_id',
model: 'foodtruck',
select: 'foodtruck_name foodtruck_location' //to exclude _id add -_id
}