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')
The above is the detailed content of Mongoose Documentation. For more information, please follow other related articles on the PHP Chinese website!