Search code examples
node.jsmongoosemongoose-schema

update multiple records in mongodb using mongoose


I have mongodb collection with below documents.

enter image description here

I wanted to update phone = 9876054321 where Email = xyz@gmail.com in Nodejs mongoose. My results should be like below. enter image description here


Solution

  • if the Model created correctly, just try

    await Model.updateMany({ Email : "xyz@gmail.com" }, { phone : 9876054321 });
    let result = await Model.find({Email  : "xyz@gmail.com"}).lean();
    console.log(result)