These are chat archives for Automattic/mongoose

22nd
Mar 2018
Irfan Raza
@irfaan008
Mar 22 2018 06:11
Hi Everyone, I am just looking for query builder option for my update statement. I see that its available for find operation but if I want to update few fields and not the all based on the input I received in api call then how can I acheive the same

A code snippet I am expecting

var query = User.findByIdAndUpdate({ _id: req.params.id }); if(req.body.name && req.body.name!='') query.<updateMethod>("name".req.body.name); if(req.body.email && req.body.email!='') query.<updateMethod>("email".req.body.email);

Kev
@lineus
Mar 22 2018 07:31
I think you're looking for .update() @irfaan008
Kev
@lineus
Mar 22 2018 07:41
@irfaan008 here is a simple example.
Irfan Raza
@irfaan008
Mar 22 2018 10:41
Ohhh Nice. I believe this will solve my problem
Thanks..
Kev
@lineus
Mar 22 2018 10:55
you're welcome!