Reputation: 845
My user schema is
{
widgets: [
{
commands: [
{
name: 'delete'
}
]
}
],
name: 'John',
}
and I want to delete widgets.commands by id. I use mongoose. I know the id but when I make the pull request it doesn't delete it.
$pull: {widgets.$.commands: {_id: req.params.id}}
Any suggestions?
Upvotes: 3
Views: 2898
Reputation: 23515
Here you go
update({}, {
$pull: {
'widgets.commands._id': req.params.id,
},
});
@example from doc
db.profiles.update( { _id: 1 }, { $pull: { votes: { $gte: 6 } } } )
Upvotes: 1