title: Node JS + Mongo DB: ValidationError: User validation failed: username: Path `username` is required
body: <p>When I am trying to Save/Create a New Document (User) to Mongo DB using Mongoose, I am getting the following Validation Error in spite of providing all the Values with proper DataType:</p>
  
  <p><strong>ValidationError: User validation failed: username: Path <code>username</code> is required.</strong></p>
  
  <p>I am a Beginner at Node JS and Mongo DB. Hence I am not able to understand what is going wrong.</p>
  
  <p>I have also added the following modules:</p>
  
  <ul>
  <li>Express</li>
  <li>Mongo</li>
  <li>Mongoose</li>
  <li>Body Parser</li>
  </ul>
  
  <p>Please see below for more details:</p>
  
  <p><strong>Detailed Error:</strong></p>
  
  <pre><code>{
  "errors": {
      "username": {
          "message": "Path `username` is required.",
          "name": "ValidatorError",
          "properties": {
              "type": "required",
              "message": "Path `{PATH}` is required.",
              "path": "username"
          },
          "kind": "required",
          "path": "username",
          "$isValidatorError": true
      }
  },
  "_message": "User validation failed",
  "message": "User validation failed: username: Path `username` is required.",
  "name": "ValidationError"
  }
  </code></pre>
  
  <p><strong>User Schema / Model:</strong></p>
  
  <pre><code>var mongoose = require("mongoose");
  
  var userSchema = new mongoose.Schema({
  firstName: {
      type: String,
      required: true
  },
  lastName: {
      type: String,
      required: true
  },
  username: {
      type: String,
      unique: true,
      required: true
  },
  password: {
      type: String,
      required: true
  }
  });
  
  mongoose.model("User", userSchema, "users");
  </code></pre>
  
  <p><strong>User Controller:</strong></p>
  
  <pre><code>var register = function (req, res) {
  
  console.log("Registering User.");
  
  var firstName = req.body.firstname;
  var lastName = req.body.lastname;
  var userName = req.body.username;
  var password = req.body.password;
  
  User
      .create({
          firstName: firstName,
          lastName: lastName,
          userName: userName,
          password: password
      }, function (err, user) {
          if (err) {
              console.log("Error creating User: ", err);
              res
                  .status(400)
                  .json(err)
          } else {
              console.log("User Created: ", user);
              res
                  .status(201)
                  .json(user)
          }
      })
  };
  </code></pre>
  
  <p>I just don't understand, why I am getting this Validation Error.
  Can anybody please guide me through this. Thanks for the help.</p>