2016-11-18 3 views
1

Mein Benutzerschema istMongoose ziehen verschachtelte Array

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

und ich möchte widgets.commands von ID löschen. Ich benutze Mangusten. Ich kenne die ID, aber wenn ich die Pull-Anfrage mache, lösche ich sie nicht. $pull: {widgets.$.commands: {_id: req.params.id}} Irgendwelche Vorschläge?

Antwort

0

Hier gehen Sie

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

$pull mongoDB documentation

@example von doc

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