Create Models Step-6

Create Models Step-6

Step 6: -Create Models

  1. Crete a new folder with name models
  2. Create a new file inside folder route with any name like teamMember.js
// import mongoose
const mongoose =require('mongoose');
// cretate schema with any name
const teamMemberSchema = new mongoose.Schema({
    name:{
        type : String,
        required:[true,'Please enter name'],
        trim:true,
        maxlength: [50,'name cant be more than 50 charcter']
    },
    email:{
        type:String,
        required:[true,'Please add avalid Email'],
        match:[/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/,'Please enter valid Email']
         },
    designation:{
        type : String,
        required:[true,'Please enter designation'],
        trim:true
         },
    description:{
        type:String,
        required:[true,'your enter your assignment description'],
        trim:true
         },
    image:{
        type:String,
        required:[true,'Please enter name'],
    },
    url:{
        type:String,
        match:[/[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi,'Please enter valid URL']
    },
    created:{
        type:Date,
        default:Date.now
    }
});
//export module with 2 parameter first is table name and second is schema name
module.exports=mongoose.model('teamMember',teamMemberSchema);

Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

*

*