Modifying mongoose query objects
Mongoose is quite easy to use, but modifying or annotating a query result manually is a little tricky. The problem is that the result objects are mongoose documents that can't be modified at will.
In my case I was trying to change a Date type field to a human readable string. So here's a way to make the object editable:
SomeModel.find({}, function (err, results) {
results.forEach(function (instance, index, array) {
array[index] = instance.toObject();
array[index].foo = '<some method or value>';
});
});
1 comment
Reply