node.js - update multiple records using mongoose in node with dynamic query -
i gone through below answers:- update multiple records using mongoosejs in node
update multiple docs different values
but in case query dynamic , means need query dynamically based on obj, not sure if foreach goof solution there better alternative same, taking time in each time.
req.body.foreach(function (obj) { mymodel.find( { country: obj.country, product: obj.product, month: parseint(obj.month), } ).update({ $set: { value: parseint(obj.value), 'lastmodified': date.now() } }, { upsert: true}, function (err) { //callback(); if (err) { return res.status(500).send(err); } return res.status(200); } );
don't know if helpful looked weren't sure parsing req.body
find documents. pseudo code. maybe give idea.
app.put("/post", function(req, res){ mymodel.find({ country : req.body.country, product : req.body.product, month : parseint(req.body.month) }) mymodel.save(function(err, results){ if(err) console.log(err); console.log(results) res.send(results) }) })
Comments
Post a Comment