title: Mongoose - Create and Insert data to new collection
body: <p>Now I am a beginner in MEAN.io. I am using <code>mongoose</code> to insert data to DB. And I follow the code from <a href="http://modernweb.com/2014/04/21/mean-stack-a-quick-start-guide/" rel="nofollow noreferrer">here.</a></p>
  <p>In my <code>app.js</code></p>
  <pre><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  var ObjectId = Schema.ObjectId;
  var Factory = require('./module.factory.js');
  mongoose.connect('mongodb://localhost/angular');
  var db = mongoose.connection;
  var dbCollection = db.collections;
  var factory = new Factory(Schema,mongoose);
  factory.createSchemas();
  </code></pre>
  <p>In <code>module.factory.js</code></p>
  <pre><code>var Factory = function(Schema,mongoose) {
  this.Schema = Schema;
  this.mongoose = mongoose;
  this.Item = null;
  
  this.createSchemas = function() {
  
      var PersonSchema = new this.Schema({
          first_name: String,
          last_name: String, 
          city: String,
          state: String
      });
      this.Person = mongoose.model('Person',PersonSchema);
  };
  
  this.getPerson = function(query,res) {
      this.Person.find(query,function(error,output) {
          res.json(output);
      });
  };
  
  this.doLogin = function(query,res) {
      this.Person.findOne(query,function(error,output) {
      console.log(query);
          res.json(output);
      console.log(output);
      });
  };
  };
  module.exports = Factory;
  </code></pre>
  <p>For inserting data:</p>
  <pre><code>app.post('/insert', function (req, res) {
  req.addListener('data', function(message)
      {
          var command = JSON.parse(message);
          var document = {first_name: command.fname,
              last_name: command.lname,
              city: command.city,
              state: command.state};
          dbCollection.user.insert(document,function(err, records){
          res.send('Inserted');
          });
      });
  });
  </code></pre>
  <p>It throws an error of <code>TypeError: Cannot call method 'insert' of undefined</code></p>
  <p>But if I put <code>dbCollection.people.insert</code>, it works fine. Can anyone tell me how to create new collection and insert data into that.</p>