title: Multiple model values on a single controller in mongoose
body: <p>I have created 3 models for nested type schema. Now I want to save only two module details in controller. How can I do that.</p>
  
  <p><strong>Models:-</strong></p>
  
  <p><strong>// users model</strong></p>
  
  <pre><code>var userModelSchema = new mongoose.Schema({
      email :     {
                  type: String,
                  required: "Email can't be empty.",
                  unique: true
                  },
      password:   {
                  type: String,
                  required: "First name can't be empty."
                  },
      firstName : {
                  type: String,
                  required: "First name can't be empty."
                  },
      lastName :  {
                  type: String,
                  required: "Last name can't be empty."
                  },  
      phoneNumber :   {
                      type: String,
                      required: "Reqired for further contact. Can't be empty."
                      },          
      verified:   { 
                  type: Boolean, 
                  default: false 
                  },
      role: String,
      emailResetToken: String,
      emailExpires: Date,
      saltSecret: String //this is user for encryption and decryption of password
      })
  mongoose.model('users', userModelSchema ,'users' );
  </code></pre>
  
  <p><strong>//admin model</strong></p>
  
  <pre><code>var adminModelSchema = new mongoose.Schema({
      email :     {
                  type: String,
                  required: "Email can't be empty.",
                  unique: true
                  },
      password:   {
                  type: String,
                  required: "First name can't be empty."
                  },
      firstName : {
                  type: String,
                  required: "First name can't be empty."
                  },
      lastName :  {
                  type: String,
                  required: "Last name can't be empty."
                  },  
      phoneNumber :   {
                      type: String,
                      required: "Reqired for further contact. Can't be empty."
                      },
      designation :   {
                      type: String,
                      required: "Designation can't be empty."
                      },          
      verified:   { 
                  type: Boolean, 
                  default: false 
                  },
      role: String,
      emailResetTokenn: String,
      emailExpires: Date,
      saltSecret: String,
      users : [{
                  type : mongoose.Schema.Type.ObjectId,
                  ref:'users'
              }]
  });
  </code></pre>
  
  <p><strong>//company model</strong></p>
  
  <pre><code>var companyModelSchema = new mongoose.Schema({
          companyName : {
                  type: String,
                  required: "Company  name can't be empty.",
                  required: false
                  },  
          companyID:  {
                      type: String,
                      },              
          address :   {
                      type: String,
                      required: "Address can't be empty.",
                      },
          contactDetails : {
                      type: String,
                      required: "Company contact number can't be empty.",
                      },
          admin : {
                      type : mongoose.Schema.Type.ObjectId,
                      ref:'admin '
                      }  
      });
  mongoose.model('company',companyModelSchema ,'company');
  </code></pre>
  
  <p><strong><em>So now, I want to use admin and company details to pass in controller where as the user will be empty <code>[]</code> as of now. How can I mention 2 model <code>admin</code> and <code>company</code> on a single controller ?</em></strong></p>
  
  <p>For single model i felt no issue . How can I do for more than one model ?</p>
  
  <pre><code>    const mongoose = require ('mongoose');
      const users = mongoose.model('users');
      const admin = mongoose.model('admin');
      const company = mongoose.model('company');
      var MongoClient = require('mongodb').MongoClient;
  
      module.exports.registerAdmin = (req, res, next) =&gt;{ 
  
              var company = new company();
              company.companyName = req.body.companyName;
              company.address = req.body.address;
              company.contactDetails  = req.body.contactDetails;
                  ?? admin.email = req.body.email;
                  ?? admin.firstName = req.body.firstName;
                  ?? admin.lastName = req.body.lastName;
                  ?? admin.phoneNumber = req.body.phoneNumber;
                  ?? admin.designation = req.body.designation;
                  ?? admin.role = "admin";
                  ?? admin.id = req.body._id;         
          }
  admin.save((err, doc) =&gt; {})
  </code></pre>