1.Mongoose is an ODM(object data modeling) library for mongoDB and Node.js,
higher level of abstraction for mongodb.2.**Features:** schemas to model data and relationship,easy data validation,
simple query Api,middleware etc.3.**Schema**(describe structure of data) into
**Model**(wapper for schema,providing interfacefor crud operation)//==== 4)Creating simple tour model===//server.jsconst mongoose=require('mongoose')const tourSchema=newmongoose.Schema({//basicname:String,rating:Number,price:Number,//using schema type optionsname:{type:String,required:[true,'A tour must have a name']},rating:{type:Number,default:4.5},price:{type:Number,required:true}})constTour= mongoose.model('Tour',tourSchema);
const mongoose =require('mongoose');run().catch(error=>console.log(error.stack));asyncfunctionrun(){await mongoose.connect('mongodb://localhost:27017/test',{useNewUrlParser:true});// Clear the database every time. This is for the sake of example only,// don't do this in prod :)await mongoose.connection.dropDatabase();const customerSchema =newmongoose.Schema({name:String,age:Number,email:String});constCustomer= mongoose.model('Customer', customerSchema);awaitCustomer.create({name:'A',age:30,email:'a@foo.bar'});awaitCustomer.create({name:'B',age:28,email:'b@foo.bar'});// Find all customersconst docs =awaitCustomer.find();console.log(docs);}