title: Mongoose dynamic mongodb collection name
body: <p>I am using mongoose driver for mongodb on node.js. I have a schema as below.</p>
  
  <p>Using db.model I can get the model with the hardcoded collection name "aggregation". It works fine. </p>
  
  <p>But how do I use the schema/model with a dynamic on-demand collection name? Basically, I will need to define a new collection on-demand and it will use the same schema.</p>
  
  <p>aggregationmodel.js</p>
  
  <pre><code>var mongoose    = require('mongoose');
  
  var db = mongoose.createConnection(configfile.mongodb.uriAggregation);
  
  var aggregationSchema = mongoose.Schema({
  
      factorname   : { type: String, index: true },
      active       : { type: Boolean},
  
      total   : [{
              _id : { type: Number, index: true },
              ordervolume : Number,
              ordertips : Number,
              ordernationality : String,
              ordercancelled : Number
             }
            ]    
  });
  
  module.exports = db.model('aggregation', aggregationSchema, 'aggregation');
  </code></pre>
  
  <p>controller.js (this file references to model)</p>
  
  <pre><code>var Aggregates     = require('../models/aggregationmodel.js');
  </code></pre>