I am running a special query in which I want transform the results after.
User.find({}, function(err, users) {
// I want to remove/add some properties from/to each user here
});
Is there a way to transform an array of documents? Also this is a special case so I do not want to apply a transformation to the Schema, which I think would transform each document like I want, but would also affect all other queries to the User model.
Basically I want the ability to perform a one time transformation on the array of docs returned.
User.find({}, function(err, users) {
// I want to remove/add some properties to each user here
users.toJSON({transform: function(doc,ret,options) { /* do tranform*/ });
// That will not work as I get an error that toJSON is not defined for that
// array that was returned.
});
I might be able to fake it out by adding a transformation right before I query and then removing that transformation when the query is complete, but that is a pretty bad hack IMHO.
Ideas? Did I miss something in the docs?