title: Mongoose - Cannot call method 'findOne'
body: <p>I'm trying to add Facebook login using passport and i'm stuck at the following error:</p>
  
  <p><strong>TypeError: Cannot call method 'findOne' of undefined at Strategy._verify</strong></p>
  
  <p>I have required <strong>models.js</strong> in my app.js file and i'm passing into the passport model</p>
  
  <p><strong>app.js</strong></p>
  
  <pre><code>var Models = require('./config/models');
  require('./config/passport')(passport,loginStrategies,Models);
  </code></pre>
  
  <p>My passport model - <strong>passport.js</strong>:</p>
  
  <pre><code>module.exports = function(passport, loginStrategies, Models){
     //Passport serialize and deserialize user
  
     passport.use(new loginStrategies.FacebookStrategy({
        //FB App Config
      },function(token, tokenSecret, profile, done) {
  
      Models.User.findOne({uid: profile.id}, function(err, user) {
        if(user) {
          done(null, user);
        } else {
          var user = new Models.User();
  
          user.uid = profile.id;
          user.name = profile.displayName;
          user.email = profile.email;
  
          user.save(function(err) {
            if(err) {
              throw err;
            }
            done(null, user);
          });
        }
      });
  
      // ...
  </code></pre>
  
  <p><strong>Models.js</strong></p>
  
  <pre><code>var mongoose = require("mongoose");
  var Schema = mongoose.Schema;
  module.exports = function(){
  
      DB_URL = "mongodb://localhost/test";
  
      //User Schema
  
      var UserSchema = new Schema({
          uid: Number,
          name: String,
          email: String,
      });
  
  
      mongoose.connect(DB_URL);
  
      mongoose.model('User', UserSchema);
  
      return{
          User : mongoose.model('User')   
      }; 
  
  };
  </code></pre>