{"action":"created","issue":{"url":"https://api.github.com/repos/feathersjs/feathers-mongoose/issues/16","labels_url":"https://api.github.com/repos/feathersjs/feathers-mongoose/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/feathersjs/feathers-mongoose/issues/16/comments","events_url":"https://api.github.com/repos/feathersjs/feathers-mongoose/issues/16/events","html_url":"https://github.com/feathersjs/feathers-mongoose/pull/16","id":36634369,"number":16,"title":"Refactored the code to allow the use of the mongoose plugins","user":{"login":"haohello","id":134774,"avatar_url":"https://avatars.githubusercontent.com/u/134774?v=3","gravatar_id":"","url":"https://api.github.com/users/haohello","html_url":"https://github.com/haohello","followers_url":"https://api.github.com/users/haohello/followers","following_url":"https://api.github.com/users/haohello/following{/other_user}","gists_url":"https://api.github.com/users/haohello/gists{/gist_id}","starred_url":"https://api.github.com/users/haohello/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haohello/subscriptions","organizations_url":"https://api.github.com/users/haohello/orgs","repos_url":"https://api.github.com/users/haohello/repos","events_url":"https://api.github.com/users/haohello/events{/privacy}","received_events_url":"https://api.github.com/users/haohello/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2014-06-27T04:00:27Z","updated_at":"2015-08-05T05:24:46Z","closed_at":"2015-08-05T05:24:46Z","pull_request":{"url":"https://api.github.com/repos/feathersjs/feathers-mongoose/pulls/16","html_url":"https://github.com/feathersjs/feathers-mongoose/pull/16","diff_url":"https://github.com/feathersjs/feathers-mongoose/pull/16.diff","patch_url":"https://github.com/feathersjs/feathers-mongoose/pull/16.patch"},"body":"Refactored the code to allow the use of the mongoose plugins, also update the package dependencies, test and example code to the latest.\r\n\r\nWell, I have such a usage scenario to use mongoose plugins and also add custom model methods in my models as such:\r\n```javascript\r\n\r\n// Get Mongoose\r\nvar mongoose = require('mongoose');\r\n\r\n// Connect to your MongoDB\r\nmongoose.connect('mongodb://localhost/user-todos');\r\n\r\nvar mongooseService = require('feathers-mongoose');\r\n\r\nvar Schema = mongoose.Schema;\r\n\r\nvar timestamps = require('mongoose-timestamp');\r\n\r\nvar Token = new Schema({\r\n  token: {type: String},\r\n  date_created: {type: Date, default: Date.now}\r\n});\r\n\r\nToken.statics.hasExpired= function(created) {\r\n  var now = new Date();\r\n  var diff = (now.getTime() - created);\r\n  return diff > config.token.ttl;\r\n};\r\nvar TokenModel = mongoose.model('Token', Token);\r\n\r\nvar UserSchema = new Schema({\r\n  email: {type : String, required : true, index: {unique: true, dropDups: true}},\r\n  firstName: {type : String, required : true},\r\n  lastName: {type : String, required : true},\r\n  age: {type : Number, required : true},\r\n  tokens: {\r\n    type: [Token]\r\n  },\r\n  password: {type : String, required : true, select: false},\r\n  skills: {type : Array, required : true}\r\n});\r\n\r\nUserSchema.plugin(timestamps);\r\n\r\nUserSchema.statics.findUser = function(email, token, cb) {\r\n  var self = this;\r\n  this.findOne({email: email}, function(err, usr) {\r\n    if(err || !usr) {\r\n      cb(err, null);\r\n    } else if (usr.token && usr.token.token && token === usr.token.token && !TokenModel.hasExpired(usr.token.date_created)) {\r\n      cb(false, {email: usr.email, token: usr.token, createdAt: usr.createdAt, name: usr.name});\r\n    } else {\r\n      cb(new Error('Token does not exist or does not match.'), null);\r\n    }\r\n  });\r\n};\r\n\r\nUserSchema.statics.findUserByEmailOnly = function(email, cb) {\r\n  var self = this;\r\n  this.findOne({email: email}, function(err, usr) {\r\n    if(err || !usr) {\r\n      cb(err, null);\r\n    } else {\r\n      cb(false, usr);\r\n    }\r\n  });\r\n};\r\n\r\nvar UserModel = mongoose.model('User', UserSchema);\r\n```"},"comment":{"url":"https://api.github.com/repos/feathersjs/feathers-mongoose/issues/comments/127862243","html_url":"https://github.com/feathersjs/feathers-mongoose/pull/16#issuecomment-127862243","issue_url":"https://api.github.com/repos/feathersjs/feathers-mongoose/issues/16","id":127862243,"user":{"login":"ekryski","id":599019,"avatar_url":"https://avatars.githubusercontent.com/u/599019?v=3","gravatar_id":"","url":"https://api.github.com/users/ekryski","html_url":"https://github.com/ekryski","followers_url":"https://api.github.com/users/ekryski/followers","following_url":"https://api.github.com/users/ekryski/following{/other_user}","gists_url":"https://api.github.com/users/ekryski/gists{/gist_id}","starred_url":"https://api.github.com/users/ekryski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ekryski/subscriptions","organizations_url":"https://api.github.com/users/ekryski/orgs","repos_url":"https://api.github.com/users/ekryski/repos","events_url":"https://api.github.com/users/ekryski/events{/privacy}","received_events_url":"https://api.github.com/users/ekryski/received_events","type":"User","site_admin":false},"created_at":"2015-08-05T05:24:46Z","updated_at":"2015-08-05T05:24:46Z","body":"Closed by PR #18."}}