title: TypeError: Invalid value for schema path `genre.type`, got value "undefined". Please help me
body: <p>I'm learning Node.js and trying to build a simple application for movie rentals service. This is my code for defining schema for movies and it's throwing an error.</p>
  <pre><code>const Joi = require('joi');
  const mongoose = require('mongoose');
  const {genreSchema} = require('./genre');
   
  //the below line thorws error and terminal points cursor at &quot;new&quot;
  const Movie = mongoose.model('Movies',new mongoose.Schema({     
      type: String,
      required: true,
      trim: true, 
      minlength: 5,
      maxlength: 255
    },
    genre: { 
      type: genreSchema,  
      required: true
    },
    numberInStock: { 
      type: Number, 
      required: true,
      min: 0,
      max: 255
    },
    dailyRentalRate: { 
      type: Number, 
      required: true,
      min: 0,
      max: 255
    }
  }));
  
  function validateMovie(movie) {
    const schema = {
      title: Joi.string().min(5).max(50).required(),
      genreId: Joi.objectId().required(),
      numberInStock: Joi.number().min(0).required(),
      dailyRentalRate: Joi.number().min(0).required()
    };
  
    return Joi.validate(movie, schema);
  }
  
  exports.Movie = Movie; 
  exports.validate = validateMovie;
  </code></pre>
  <p>This is the <code>./genre</code>. Please check it.</p>
  <pre><code>const mongoose = require('mongoose');
  const Joi = require('joi');
  const genreSchema = new mongoose.Schema({
      name:{
          type:String,
          required:true,
          minlength: 5,
          maxlength: 50
      }
  })
  const Genre = mongoose.model('Genre', genreSchema);
  function validateGenre(genre){
      const schema = {
          name: Joi.string().min(3).required()
      };
      
       return Joi.validate(genre,schema);
  }
  exports.Genre=Genre;
  exports.validate = validateGenre;
  </code></pre>
  <p>This is <code>./rentals</code> file. It is also throwing `Object.anonymous' error.</p>
  <pre><code>const { Rental, validate } = require('../models/rental');
  const { Movie } = require('../models/movie');
  const { Customer } = require('../models/customer');
  const auth = require('../middleware/auth');
  const mongoose = require('mongoose');
  const Fawn = require('fawn');
  const express = require('express');
  const router = express.Router();
  
  Fawn.init(mongoose);
  
  router.get('/', auth, async (req, res) =&gt; {
    const rentals = await Rental.find()
      .select('-__v')
      .sort('-dateOut');
    res.send(rentals);
  });
  router.post('/', auth, async (req, res) =&gt; {
    const { error } = validate(req.body);
    if (error) return res.status(400).send(error.details[0].message);
  
    const customer = await Customer.findById(req.body.customerId);
    if (!customer) return res.status(400).send('Invalid customer.');
  
    const movie = await Movie.findById(req.body.movieId);
    if (!movie) return res.status(400).send('Invalid movie.');
  
    if (movie.numberInStock === 0)
      return res.status(400).send('Movie not in stock.');
  
    let rental = new Rental({
      customer: {
        _id: customer._id,
        name: customer.name,
        phone: customer.phone
      },
      movie: {
        _id: movie._id,
        title: movie.title,
        dailyRentalRate: movie.dailyRentalRate
      }
    });
  
    try {
      new Fawn.Task()
        .save('rentals', rental)
        .update('movies',{ _id: movie._id },{
            $inc: { numberInStock: -1 }
          })
        .run();
  
      res.send(rental);
    } 
    catch (ex) {
      res.status(500).send('Something failed.');
    }
  });
  
  router.get('/:id', [auth], async (req, res) =&gt; {
    const rental = await Rental.findById(req.params.id).select('-__v');
  
    if (!rental)
      return res.status(404).send('The rental with the given ID was not found.');
  
    res.send(rental);
  });
  
  module.exports = router;
  </code></pre>
  <p>This is the error message I'm getting. I'm on Windows and my text editor is VScode and terminal is powershell</p>
  <pre><code>PS D:\Study\Vidly&gt; node index.js
  D:\Study\Vidly\node_modules\mongoose\lib\schema.js:475
        throw new TypeError('Invalid value for schema path `' + fullPath +
        ^
  
  TypeError: Invalid value for schema path `genre.type`, got value &quot;undefined&quot;
      at Schema.add (D:\Study\Vidly\node_modules\mongoose\lib\schema.js:475:13)
      at Schema.add (D:\Study\Vidly\node_modules\mongoose\lib\schema.js:509:12)
      at new Schema (D:\Study\Vidly\node_modules\mongoose\lib\schema.js:129:10)
      at Object.&lt;anonymous&gt; (D:\Study\Vidly\models\movie.js:5:39)
      at Module._compile (internal/modules/cjs/loader.js:1063:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
      at Module.load (internal/modules/cjs/loader.js:928:32)
      at Function.Module._load (internal/modules/cjs/loader.js:769:14)
      at Module.require (internal/modules/cjs/loader.js:952:19)
      at require (internal/modules/cjs/helpers.js:88:18)
      at Object.&lt;anonymous&gt; (D:\Study\Vidly\routes\rentals.js:2:19)
      at Module._compile (internal/modules/cjs/loader.js:1063:30)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
      at Module.load (internal/modules/cjs/loader.js:928:32)
      at Function.Module._load (internal/modules/cjs/loader.js:769:14)
      at Module.require (internal/modules/cjs/loader.js:952:19)
  </code></pre>