Embedded document löschen mit mongoose
Irgendwie scheint das derzeit nicht wie dokumentiert zu klappen.
Hier ein Workaround:
// Delete Tag
app.del('/tags/:id.json', function(req, res) {
Contact.findById(req.body.contact_id, function(err, doc) {
if(!err) {
var index = 0;
doc.tags.forEach(function(item) {
if(item._id == req.params.id) {
var newTagsObj = doc.tags.toObject();
newTagsObj.splice(index,1)
Contact.update(
{ _id: req.body.contact_id },
{ 'tags': newTagsObj },
function(err) {
if(!err) {
res.send({success: true});
}
}
);
return false;
}
index += 1;
});
}
})
});
5 Notes/ Hide
-
von promontoryop3 als Favorit markiert
-
von likeitio90 als Favorit markiert
-
von jehu99 gepostet