Adding a User to the Database
First, let’s create and record a user to our database. 

Creating a User Model
We've created a user model, which is an object, with a few fields:

// models/user.js

const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
  email: {
    type: String,
    required: true,
    unique: true
  },
  password: {
    type: String,
    required: true,
    minlength: 8
  }
});

module.exports = mongoose.model('user', userSchema);