Hi;
I'm trying to add some instance methods to a Schema where there is already a collection with existing documents. I'm trying to do something like this:
var mySchema = new mongoose.Schema({
foo : Number
}, {
collection : 'myCollection'
});
mySchema.methods.addFoo = function (amount) {
console.log('adding foo: ' + amount);
};
var myModel = mongoose.model('myModel', mySchema);
And it works fine when I do:
var myDocument = new myModel({
foo : 1
});
myDocument.addFoo(1); //adding foo: 1
But, when I do this, it doesn't work:
myModel.find({_id : '123abc'}, function (err, doc) {
doc.addFoo(1); //TypeError: Object has no method 'addFoo'
});
Am I doing this wrong or did I misunterstand the use of instance method?
Thanks in advance;
Bernardo