title: how to create collection programatically in mongodb using mongoose and nodejs
body: <p>I am trying to create a collection in MongoDB programmatically but I do not know how to create it. I have one common model for schema, Using this how to create collection many collections with a different name. If anyone knows please help.</p>
  
  <p>common.model.js:</p>
  
  <pre><code> const mongoose = require('mongoose');
  
   var userSchemaOil = new mongoose.Schema({
  
      pid: {
          type: String
      },
      name: {
          type: String
      },
      weight: {
          type: String
      },
      price: {
          type: Number
      }  
  
  });
  </code></pre>
  
  <p>create.controller.js:</p>
  
  <pre><code> module.exports.createCollection = (req, res, next) =&gt; {
  
      let collectionName=req.query.collectionname; //Example: Tea
  
      module.exports = mongoose.model( collectionName, userSchemaOil);
  
     ?
  
      }
  </code></pre>