Example:
const mongoose = require('mongoose');
mongoose.connect("mongodb://localhost:27017/magesDB");
const userSchema = new mongoose.Schema( {
name: {
type: String,
require: [ true, "Please enter your name" ],
},
email: {
type: String,
require: [ true, "Please enter your email" ],
},
password: {
type: String,
require: [ true, "Please enter your password" ],
},
role: {
type: String,
enum:[ "admin", "user" ],
default: "user",
},
gender: {
type: String,
enum: [ "male", "female" ],
required: [ true, "Please enter Gender" ],
},
dob: {
type: Date,
required: [ true, "Please enter Date of birth" ],
}
} )
const USer = new mongoose.model( "User", userSchema )