mongoose delete object from array code example
Example 1: mongoose delete property
User.collection.update({_id: user._id}, {$unset: {field: 1 }});
Example 2: mongoose remove element from array
db.survey.update(
{ },
{ $pull: { results: { $elemMatch: { score: 8 , item: "B" } } } },
{ multi: true }
)
Example 3: mongoose remove document from array
Favorite.updateOne( {cn: req.params.name}, { $pullAll: {uid: [req.params.deleteUid] } } )
Example 4: mongoose delete object from array
doc.subdocs.push({ _id: 4815162342 })
doc.subdocs.pull({ _id: 4815162342 })