title: How to use mongoose discriminator with PassportJS as passwords are not being saved?
body: <p>Upon signing up using the (derived) farmer schema, the user's password is not being saved. Eveything else is being saved. Is this happening due to using PassportJS, as it is not letting save the password into the User model? I'm a beginner in MongoDB and mongoose, and any help will be appreciated.
  Below is the code for the same.</p>
  
  <p><strong><em>user.js</em></strong> (Base Schema)</p>
  
  <pre><code>const mongoose = require('mongoose');
  const Schema = mongoose.Schema;
  
  var mongooseUniqueValidator = require('mongoose-unique-validator');
  var passportLocalMongoose = require('passport-local-mongoose');
  
  const User = new Schema({
      firstname : {
          type: String,
          required: true
      },
      lastname : {
          type: String,
          required: false,
          default: "Empty last name"
      },
      admin: {
          type: Boolean,
          default: false
      }
  });
  
  User.plugin(passportLocalMongoose);
  module.exports = mongoose.model('User', User);
  </code></pre>
  
  <p><strong><em>farmer.js</em></strong>  (Derieved Schema)</p>
  
  <pre><code>const mongoose = require('mongoose');
  const Schema = mongoose.Schema;
  
  var User = require('./user');
  var mongooseUniqueValidator = require('mongoose-unique-validator');
  
  const Farmer = User.discriminator('Farmer', new Schema(
      {
          state : {
              type : String,
              required: false
          }
      })
  );
  
  module.exports = mongoose.model('Farmer');
  </code></pre>
  
  <p><strong><em>User's signup POST Operation</em></strong></p>
  
  <pre><code>router.post('/signup', (req, res, next) =&gt; {
    User.register( new User({username: req.body.username}), req.body.password,
    (err, user) =&gt; {
  
      if(err) {
        res.statusCode = 500;
        res.setHeader('Content-Type', 'application/json');
        res.json({err: err});
      }
  
      else {
        if(req.body.firstname){
          user.firstname = req.body.firstname;
        }
        if(req.body.lastname){
          user.lastname = req.body.lastname;
        }
        user.save((err, user) =&gt; {
          if(err) {
            res.statusCode = 500;
            res.setHeader('Content-Type', 'application/json');
            res.json({err: err});
            return;
          }
  
          passport.authenticate('local')(req, res, () =&gt; {
            res.statusCode = 200;
            res.setHeader('Content-Type', 'application/json');
            res.json({success: true, status: 'Registration Successful!'});
          });
  
        })
  
      }
  
    });
  });
  </code></pre>
  
  <p><strong><em>Farmer's Signup POST operation</em></strong></p>
  
  <pre><code>.post( (req, res, next) =&gt; {
      Farmer.create(req.body)
      .then((farmer) =&gt; {
          console.log('Farmer has been created ', farmer);
          res.statusCode = 200;
          res.setHeader('Content-Type', 'application/json');
          res.json(farmer);
      }, (err) =&gt; next(err))
      .catch((err) =&gt; next(err));
  })
  </code></pre>