2016-11-18 160 views
1

我的用戶模式是貓鼬拉嵌套數組

{ 
    widgets: [ 
    { 
     commands: [ 
     { 
      name: 'delete' 
     } 
     ] 
    } 
    ], 
    name: 'John', 
} 

,我想通過ID刪除widgets.commands。我用貓鼬。我知道這個id,但是當我提出pull請求時,它不會刪除它。 $pull: {widgets.$.commands: {_id: req.params.id}}有什麼建議嗎?

回答

0

在這裏你去從文檔

db.profiles.update({ _id: 1 }, { $pull: { votes: { $gte: 6 } } }) 

update({}, { 
    $pull: { 
     'widgets.commands._id': req.params.id, 
    }, 
}); 

$pull mongoDB documentation

@example