install mangoose
npm install mongoose
.
.
To connect to the mongodb by using mongoose
ex:app.js
const mongoose=require('mongoose'); mongoose .connect('url'); .then(res=>app.listen(3000)); .catch(err=>console.log(err));
.
.
To create schema
ex:model folder student.js
const mongoose = require('mongoose'); const studentSchema = mongoose.Schema({ name:{ type:String, required:true }, studentid:{ type:Number, required:true } }); module.exports=mongoose.model('students',studentSchema);
.
.
To create a students
ex:controllers folder
console.log('hi')
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3