let book2 = new Book ({ title : "Marvel Comics" , author : "stan lee" , price : 499 , category : "comics" , }) . save () . then (( res ) => { console . log ( res ); }) . catch (( err ) => { console . log ( err ); }); NOW THE CONDITIONS: title : { type : String , required : true , maxlength : 5 , }, discount : { type : Number , default : 0 , }, HERE WE DIDN'T DEFINE DISCOUNT ,BUT IN THE OUTPUT WE CAN SEE IT, AS IT IS DEFAULT category : { type : String , enum : [ "fiction" , "non-fiction" ], }, THERE ARE MANY MORE SCHEMA TYPES ,REFER:https://mongoosejs.com/docs/schematypes.html
Comments
Post a Comment