title: Mongoose/node error: Cannot read property 'ObjectId' of undefined
body: <p>I am creating a small node/express/mongo app, which allows users to post cat photos and comment on them. I have two models, <code>cat</code>, and <code>comment</code> . Everything was working fine until I decided to associate the two models together, which then caused this error:</p>
  
  <pre><code>type: mongoose.Schema.Type.ObjectId,
                              ^ 
  TypeError: Cannot read property 'ObjectId' of undefined
  </code></pre>
  
  <p>The error is referring to the cat model: </p>
  
  <pre><code>var mongoose = require('mongoose');
  
  
  var catModel = mongoose.Schema({
      name: String,
      image: String,
      owner: String,  
      description: String,
      comments: [
  
          {
              type: mongoose.Schema.Type.ObjectId,
              ref: "Comment"
  
          } 
      ]
  });
  
  var Cat = mongoose.model("Cats", catModel);
  
  module.exports = Cat;
  </code></pre>
  
  <p>Here is the comment model :</p>
  
  <pre><code>var mongoose = require('mongoose');
  
  var commentSchema = mongoose.Schema({
  
      username: String,
      content: String,
  });
  
  
  Comment = mongoose.model('Comment', commentSchema);
  
  module.exports = Comment;
  </code></pre>
  
  <p>Here is a snippet of app.js :</p>
  
  <pre><code>var express = require('express');
  var app = express();
  //more modules
  var Comment = require('./models/comment.js');
  var Cat = require('./models/cat.js');
  
  
  //home route 
  
  app.get('/cats', function(req,res) {
  
      Cat.find({}, function(err, cats) {
          if (err) {
              console.log(err);
  
          } else {
            res.render('cats', {cats: cats});  
          }  
      })
  });
  </code></pre>
  
  <p>I am using mongoose 4.3.7 . I researched this problem and couldn't solve it. For example, I looked at <a href="https://stackoverflow.com/questions/7936845/mongoose-error-cannot-read-property-objectid-of-undefined">this</a> post and re-installed mongoose, but the problem persisted.</p>