remove an array element in mongodb code example
Example 1: $pull mongoose
TemplateDoc.findOneAndUpdate(
{ userId: _id },
{ $pull: { templates: { _id: templateid } } },
{ new: true }
)
.then(templates => console.log(templates))
.catch(err => console.log(err));
Example 2: mongoose remove document from array
Favorite.updateOne( {cn: req.params.name}, { $pullAll: {uid: [req.params.deleteUid] } } )