Is there a way to write this part better?
'update': function (req, res) {
var item = req.body.item;
var tags = [];
tag.find(function (err, _tags) {
tags = _tags;
post.update({ '_id': item._id }, { $set: { Text: item.Text } }, function (e1, r1) {
post.update({ '_id': item._id }, { $pullAll: { Tags: tags } }, function (e2, r2) {
post.update({ '_id': item._id }, { $pushAll: { Tags: item.Tags } }, function (e3, r3) {
if (r3 === 1) {
res.json(true);
}
});
});
});
});
}
Post
has array of tags, and i want to update tags, i get all tags, and $pullAll
them to empty the array of item tags, then $pushAll
to fill again, i don't want to append new tags, because it's an update method, above code works as expected, but guess it's a bit incorrect