title: Validation failed nodejs required field
body: <p>I am creating creating a bookstore demo app in Node.js. I have ran into a little situation with the POST request for creating a genre. I've setup so the name of the genre must be required if not don't insert it to the database. But when I use Postman to POST to the url localhost:3000/api/genres with the JSON</p>
  
  <pre><code>{
    "name": "TEST"
  }
  </code></pre>
  
  <p>It throws an error</p>
  
  <pre><code>{
    "error": "Genre validation failed"
  }
  </code></pre>
  
  <p>When I remove the required field in the genreSchema it works but the name  of the genre doesn't appear. Here is my code</p>
  
  <p>Code:</p>
  
  <p>genre.js</p>
  
  <pre><code>var mongoose = require("mongoose");
  
  
  // Create a schema for genre
  var Schema = mongoose.Schema;
  
  var genreSchema = Schema({
      name:{ 
          type: String, 
          required: true 
      },
      create_date:{ 
          type: Date, 
          default: Date.now 
      }
  });
  var Genre = module.exports = mongoose.model("Genre", genreSchema);
  
  // Methods
  
  // get genres 
  module.exports.getGenres = function(callback, limit) {
      Genre.find(callback).limit(limit);
  };
  // add a new genre
  // TODO: Not working in Postman ValidationError
  module.exports.addGenre = function(genre, callback) {
      Genre.create(genre, callback);
  };
  </code></pre>
  
  <hr>
  
  <p>app.js</p>
  
  <pre><code>var express = require("express");
  var app = express();
  var bodyParser = require("body-parser");
  var mongoose = require("mongoose");
  var Genre = require('./models/genre');
  var Book = require('./models/book');
  // Connect to mongoose
  mongoose.connect("mongodb://localhost/bookstore");
  var db = mongoose.connection;
  
  app.get("/", function(req, res){
      res.json({ error: "Please use /api/books or /api/genres" });
  });
  
  // GET /api/genres
  app.get('/api/genres', function(req, res){
      Genre.getGenres(function(err, genres){
          if(err) {
              res.json({error: err.message})
          }
          res.json(genres);
      });
  });
  app.post('/api/genres', function(req, res){
      var genre = req.body;
      Genre.addGenre(genre, function(err, genre){
          if(err) {
              res.json({
                  error: err.message
              })
          }
          res.json(genre);
      });
  });
  // GET /api/books
  app.get('/api/books', function(req, res){
      Book.getBooks(function(err, books){
          if(err) {
              res.json({error: err.stack})
          }
          res.json(books);
      });
  });
  // GET /api/book/:id
  app.get('/api/book/:_id', function(req, res){
      Book.getBookById(req.params._id, function(err, book){
          if(err) {
              res.json({error: err.message})
          }
          res.json(book);
      });
  });
  
  
  app.listen(3000, function(){
      console.log("Running on port 3000!")
  });
  </code></pre>