Skip to main content

Update monogodb collection documents according to request array. eg: If I delete any document on ui it will also delete same document in collection

I want to update my collection documents account to ui addition, deletion or updation using same query. I have array of document which i am adding into database using following code snippet when I add new value It update in collection but when i delete any document on uI it does not update in database . I am using mongodb and mongoose .

    let threats = req.body.threat
    if (threats) {
      threats.map(async (threat) => {
        const update = {
          id: threat.id
        };
        await ProjectThreatModel.findOneAndUpdate(update, threat, {
          new: true,
          upsert: true,
          useFindAndModify: false
        })
      })
    }
Via Active questions tagged javascript - Stack Overflow https://ift.tt/SHV0ArW

Comments