I have a mongoose schema like
var userSchema = new mongoose.Schema({
friends: [String]
});
var User = mongoose.model('User', userSchema);
var alice = new User({friends: ['bob']});
and I would like to attach an instance method to the friends
array, e.g., a function myFunction
that can be called like
alice.friends.myFunction(...);
Does mongoose provide a way to do so?
PS: here, @wciu asked if a function can be defined on the subdocuments itself (which is possible). The question here is if it is possible to define it on the array.