title: Node.js mongoose .findOne is not a function
body: <p>In my app, I do return promise with my mongoose model:</p>
  
  <pre><code>var roomModel = require('../../../models/room').roomModel;
  
  roomModel.findOne({ name: req.body.roomName })
      .then(
          (room) =&gt; {
              return new Promise(function(resolve, reject) {
                  //if no room present, create one, if present, check password
                  if (room) {
  
                      if (room.password === req.body.roomPassword) {
                          return resolve(room);
                      } else {
                          return reject({
                              code: 401,
                              message: 'Room password not correct'
                          });
                      }
                  } else {
                      // create new room with given data
                      var newRoom = roomModel({});
                      newRoom.name = req.body.roomName;
                      newRoom.password = req.body.roomPassword;
                      //newRoom.users = [];
                      newRoom.users[0] = {
                          name: req.body.userName
                      };
  
                      newRoom.save()
                          .then((data) =&gt; {
                              console.log(data);
                              if (!data) {
                                  return reject({
                                      code: 500,
                                      message: 'Error when saving room'
                                  });
                              } else {
                                  return resolve(newRoom);
                              }
                          });
                  }
              });
          }
      )
      .then((room) =&gt; {
          room.findOne({ 'users.name': req.body.userName })
              .then((user) =&gt; {
                  console.log(user);
              });
      })
  </code></pre>
  
  <p><strong>room.js model:</strong></p>
  
  <pre><code>'use strict';
  var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  var userSchema = require('./user').userSchema;
  
  var room = new Schema({
      name: String,
      password: String,
      users: [userSchema]
  });
  
  module.exports.roomSchema = room;
  module.exports.roomModel = mongoose.model('room', room);
  </code></pre>
  
  <p><strong>users.js model:</strong></p>
  
  <pre><code>    var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  
  var user = new Schema({
      name: String
  });
  
  module.exports.userSchema = user;
  module.exports.userModel = mongoose.model('user', user);
  </code></pre>
  
  <p>but when I try to call .findOne() function on this returned model, I get following error:</p>
  
  <pre><code>TypeError: room.findOne is not a function
  </code></pre>
  
  <p>is model passed in the promise not a model in <code>next .then()</code> statement? </p>