I want that if one operation inside the controller and i update the collection so then i want to call another mongodb collection (model) and then findby id and then inside it has field which has array of object so i want to changed inside that array of object where every object have the id as well i will share the code.
const payMonthlyInstallment = async (req, res) => {
const contractDetails = await Contract.findById(req.params.id).populate("customer").populate({
path : 'product',
populate : {
path : 'category'
}
});
const investerEdit = contractDetails?.investor?.map(item => item.investorDetail.toString())
const monthlyInstallment = ((((((contractDetails.product?.price - contractDetails.downPayment) * 25)/100) + (contractDetails.product?.price - contractDetails.downPayment)) / contractDetails.planOfInstallment) / investerEdit.length)
investerEdit.map(async (item) => {
const user = await client.db("test").collection("investors").aggregate([
{ $match: { _id: ObjectId(item) } },
]).toArray()
// const investor = Investor.findOne({_id: item});
console.log("investerEdit", user)
// const contracts = investor
})
console.log(monthlyInstallment ,investerEdit,investerEdit.length)
res.send("contract");
}