Kindly wait a moment, post will be visible in just 5 seconds.

No Preview

Entertainment & Education

Posted on 15 February 2022

How to update deep nested Arrays in MongoDB?

Ad Banner
No Preview

Hi Everyone,

Have been trying to update a nested Array in mongoDB but unsuccesssful , can anyone guide me to get the desired output achieved;

sending above parameters from frontEnd.

with above req.body and function =>>>>>> below is response

I am getting this success msg as modified content . But still in DB it is unchanged .

screenshot of DB structure is attached for reference .

Hope I get help from here or if anyone facing similar issue.

Thank You

0

155

0

No Preview

Entertainment & Education

Explore more similar Post

1 Comments

Entertainment & Education

16 February 2022

I have the solution, sorry for the trouble. I have changed the functionality to :::: exports.updateOrder = (req, res) => { Order.update( {}, { $set: { "packedStatusWithDiffSellers.$[x].sellerOrderStatus.$[y]": { type: req.body.type, date: new Date(), isCompleted: true } } }, { arrayFilters: [ { "x.sellerId": { "$eq": req.body.sellerId } }, { "y.type": { "$eq": req.body.type }, "y.isCompleted": { "$eq": "false" } } ], multi: true }).exec((error, order) => { if (error) return res.status(400).json({ error }); if (order) { res.status(201).json({ order }); } }); }; and sent req.body = { sellerId: "6203e4bd60659b37ebeb7569", type: "packed" }

1
REPLY