feathersjs/feathers-mongoose — pull request #16 by haohello (2014-06-27 04:00:27+00:00)
Title: Refactored the code to allow the use of the mongoose plugins

Refactored the code to allow the use of the mongoose plugins, also update the package dependencies, test and example code to the latest.

Well, I have such a usage scenario to use mongoose plugins and also add custom model methods in my models as such:
```javascript

// Get Mongoose
var mongoose = require('mongoose');

// Connect to your MongoDB
mongoose.connect('mongodb://localhost/user-todos');

var mongooseService = require('feathers-mongoose');

var Schema = mongoose.Schema;

var timestamps = require('mongoose-timestamp');

var Token = new Schema({
token: {type: String},
date_created: {type: Date, default: Date.now}
});

Token.statics.hasExpired= function(created) {
var now = new Date();
var diff = (now.getTime() - created);
return diff > config.token.ttl;
};
var TokenModel = mongoose.model('Token', Token);

var UserSchema = new Schema({
email: {type : String, required : true, index: {unique: true, dropDups: true}},
firstName: {type : String, required : true},
lastName: {type : String, required : true},
age: {type : Number, required : true},
tokens: {
type: [Token]
},
password: {type : String, required : true, select: false},
skills: {type : Array, required : true}
});

UserSchema.plugin(timestamps);

UserSchema.statics.findUser = function(email, token, cb) {
var self = this;
this.findOne({email: email}, function(err, usr) {
if(err || !usr) {
cb(err, null);
} else if (usr.token && usr.token.token && token === usr.token.token && !TokenModel.hasExpired(usr.token.date_created)) {
cb(false, {email: usr.email, token: usr.token, createdAt: usr.createdAt, name: usr.name});
} else {
cb(new Error('Token does not exist or does not match.'), null);
}
});
};

UserSchema.statics.findUserByEmailOnly = function(email, cb) {
var self = this;
this.findOne({email: email}, function(err, usr) {
if(err || !usr) {
cb(err, null);
} else {
cb(false, usr);
}
});
};

var UserModel = mongoose.model('User', UserSchema);
```