title: Mongoose: "TypeError: Undefined type at"
body: <p>I have a module that uses mongoose. My main project also uses mongoose. I found out that I can not use module's connection with my project's schema. See the example:</p>
  
  <pre><code>var mod = require('module_with_mongoose_connection');
  var mongoose = require('mongoose');
  
  var SessionSchema = new mongoose.Schema({ // replacing this with `mod.mongoose.Schema` works
  ...
  });
  mod.mongooseConnection.model('session', SessionSchema);
  </code></pre>
  
  <p>The example above throws</p>
  
  <pre><code>    throw new TypeError('Undefined type at `' + path +
            ^
  TypeError: Undefined type at `paths.name`
    Did you try nesting Schemas? You can only nest using refs or arrays.
      at Function.Schema.interpretAsType (/Users/me/Work/me/nodejs/orm-model/node_modules/mongoose/lib/schema.js:397:11)
      at Schema.path (/Users/me/Work/me/nodejs/orm-model/node_modules/mongoose/lib/schema.js:334:29)
      at Schema.add (/Users/me/Work/me/nodejs/orm-model/node_modules/mongoose/lib/schema.js:245:12)
      at Schema.add (/Users/me/Work/me/nodejs/orm-model/node_modules/mongoose/lib/schema.js:240:14)
      at new Schema (/Users/me/Work/me/nodejs/orm-model/node_modules/mongoose/lib/schema.js:72:10)
  Why is that? A bug?
  </code></pre>
  
  <p>What's the solution to this problem? A bug?</p>