LearnBoost/mongoose — Issue #669: help on statics
Author: nnarasimha
Created: 2012-01-02 21:06:04+00:00
State: open

Can someone explain how I can use statics to return a model? Below is my user schema but I am getting undefined when I try to access my user properties.

require('./db_connect');

//User schema

var UserSchema = new Schema({
first_name : {type:String},
last_name : {type:String},
email : {type:String, required: true},
password: {type:String, required: true},
}), User;

/*Helper methods*/

UserSchema.statics.findByEmail = function(email, callback) {
return this.find({email:email}, callback);
}

var exports = module.exports = mongoose.model('User', UserSchema);