How should i populate a field with string value instead of nested object?
Here is the code i am currently using to populate-
<code> const voucherNoFoundResponse = await StockOrder.findOne({_id: voucherID})
.populate({
path: 'entries.item',
select: 'desc.name -_id',
}).lean()
</code>
<code> const voucherNoFoundResponse = await StockOrder.findOne({_id: voucherID})
.populate({
path: 'entries.item',
select: 'desc.name -_id',
}).lean()
</code>
const voucherNoFoundResponse = await StockOrder.findOne({_id: voucherID})
.populate({
path: 'entries.item',
select: 'desc.name -_id',
}).lean()
But this is giving me this nested object –
<code>voucherNoFoundResponse.entries[0].item.desc.name
</code>
<code>voucherNoFoundResponse.entries[0].item.desc.name
</code>
voucherNoFoundResponse.entries[0].item.desc.name
How should i trim the fat and get the final result as a string inside voucherNoFoundResponse.entries[0].item
New contributor
El Calvin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1