Promise.all with nested map.. First map only work others return empty objects in mongoose nodejs iam using only one promise.all to warp both maps
This this code
let foundCategory = await Category.findOne({_id: req.params.id})
let CategoryWithSections = {...foundCategory.toObject(),sectionsOfCategory:
//this map work
await Promise.all( foundCategory.sectionsOfCategory.map(async(SOC)=>{
let sections= await Section.findOne({_id: SOC.sectionOfCategory })
return {...sections.toObject(), productsOfSections:
//this map doesn't work
sections.productsOfSection.map(async(POS)=>{
return await Product.findOne({_id: POS.productOfSection })
})
}
// return await sections.filter((section) => section._id === SOC.sectionOfCategory)
}) ) }