title: NodeJS - Mongoose document embedding
body: <p>I am trying to practice Mongoose and Node JS, I want to use Comment schema in Article schema and when I run the server, it just throws an error like this: </p>
  
  <blockquote>
    <p>Invalid value for schema Array path <code>comments</code></p>
  </blockquote>
  
  <p>Here is my Comment model</p>
  
  <pre><code>module.exports = function( mongoose ) {
  
      var Schema = mongoose.Schema;
  
      var CommentSchema = new Schema({
          text: String,
          author: String,
          createDate: {
              type: Date,
              default: Date.now
          }
      });
  
      console.log("********");    
      console.log(CommentSchema);
      console.log("********");
  
      mongoose.model( 'Comment', CommentSchema);
  };
  </code></pre>
  
  <p>And my Article model:</p>
  
  <pre><code>module.exports = function(mongoose){
      var Schema = mongoose.Schema;
      var Comment = require("./Comment");
  
      console.log("--------");
      console.log(mongoose);
      console.log("--------");
  
      var ArticleSchema = new Schema({
          title: String,
          content: String,
          author: String,
          comments: [Comment.schema],
          createDate: {
              type: Date,
              default: Date.now
          }
      });
      mongoose.model('Article', ArticleSchema);
  };
  </code></pre>
  
  <p>They are in the same folder called "models".</p>
  
  <p>And finally my app.js to show the bindings:</p>
  
  <pre><code>var express = require('express');
  var morgan = require("morgan");
  var methodOverride = require("method-override");
  var utils = require("./lib/utils");
  var config = require("config");
  var bodyParser = require('body-parser');
  var app = express();
  var mongoose = require('mongoose');
  var mongooseConnection = utils.connectToDatabase(mongoose, config.db);
  var routes = require('./routes/index');
  var users = require('./routes/users');
  
  var app = express();
  
  // view engine setup
  app.set("port", process.env.PORT || 3000);
  
  app.use(express.static(__dirname + '/public'));
  app.use(morgan('dev'));
  app.use(bodyParser());
  app.use(methodOverride());
  
  app.set('views', __dirname + '/views');
  app.set('view engine', 'jade');
  app.set('view options', { layout: true});
  
  require("./controllers/ArticleController")(app, mongooseConnection);
  require("./controllers/CommentController")(app, mongooseConnection);
  require("./controllers/IndexController")(app, mongooseConnection);
  
  require("./models/Article")(mongooseConnection);
  require("./models/Comment")(mongooseConnection);
  require("./models/User")(mongooseConnection);
  
  app.listen(app.get("port"), function(){
      console.log("Express server listening on port" + app.get("port"));
  });
  </code></pre>
  
  <p>Thanks.</p>