$pull mongoose 1

$pull mongoose

TemplateDoc.findOneAndUpdate(
    { userId: _id },
    { $pull: { templates: { _id: templateid } } },
    { new: true }
  )
    .then(templates => console.log(templates))
    .catch(err => console.log(err));

Here is what the above code is Doing:
1. We are finding the user by the id.
2. We are using the $pull operator to remove the template from the templates array.
3. We are using the new: true option to return the updated document.

Similar Posts