I'm trying to figure out how to load a user based on ID with mongoose in a node application. I come from a php/mysql background and I'm having a hard time figuring out how to tie this all together in node+mongoose. Can someone help me to improve/fix this example?
Model models/user.js
var mongoose = require('mongoose')
, Schema = mongoose.Schema;
var userSchema = new Schema({
facebookProfile: {},
facebookPages: { type: Array },
created: {type: Date, default: Date.now}
});
userSchema.methods = {
getManagedPages: function(){
return this.facebookPages;
}
}
userSchema.statics = {
load: function(userid){
return this.findById(userid);
}
}
module.exports = mongoose.model('User', userSchema);
in the controller controllers/user.js
var User = mongoose.model("User");
var currentUser = new User();
currentUser = currentUser.load(req.user._id);
The error I'm getting is:
TypeError: Object { _id: 52861322f38d7ded3f000001, created: Fri Nov 15 2013 13:27:14 GMT+0100 (CET), facebookPages: [] } has no method 'load' at exports.profile