This is my script, I don’t know why when I use asysc await with rawCollection when I get data inside loop and then I set new properties (poTmp) inside I get data but after i set new properties I console outside it do not set new prop why?
let items = await Items.rawCollection()
.aggregate([
{
$match: match,
},
])
.toArray()
items.forEach(async item => {
let po = await PurchaseOrderDetails.rawCollection()
.aggregate([
{
$match: {
itemId: item._id,
tranDate: { $lte: tDate },
},
},
{
$group: {
_id: '$itemId',
itemDoc: { $last: item },
onHandPO: { $sum: '$qtyBase' },
},
},
{
$group: {
_id: '$itemId',
itemDoc: { $last: '$itemDoc' },
lastOnHandPO: { $last: '$onHandPO' },
},
},
])
.toArray()
//==================
//set new properties
//==================
item.poTmp = po[0]
})
console.log(items)
return items