How can I modify an object returned by a Mongoose query?
Assume we have the following schema:
var S = new mongoose.Schema( { 'name': String, 'field': String } );
I do the following query and modification to the result:
var retrieve = function(name, callback) {
S.findOne({ name: name }).exec(function (err, obj) {
if (err) return handleError(err);
obj['field'] = 'blah';
callback(obj);
});
}
The obj.field
will not contain blah
but the original value returned by the query, as if it was read-only. What is going on?
Note: my environment is Node.js, Express, Mongoose and MongoDB