D
D
deadkEEper12016-02-27 17:28:34
MongoDB
deadkEEper1, 2016-02-27 17:28:34

How to give a mongoose method to a model?

Let's say there is a minimal mongo model

var Schema = mongoose.Schema;

var userSchema = new Schema({
name: String
})

userShema.methods.say = function(){
console.log('hello')
}

var User = mongoose.model('users', userSchema);

module.exports = User;

But when I try to access the method from the client, I get an error that there is no such method (this.model.say is not a function)
And when even in the browser console model (this.model) there is no say method anywhere, neither in obj nor in it __proto__ .
I suspect that the problem is in my misunderstanding of the work of callbacks. Please explain in simple terms
Thank you

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question