Home  >  Article  >  Web Front-end  >  Mongoose Documentation

Mongoose Documentation

WBOY
WBOYOriginal
2024-08-06 18:45:22383browse

Mongoose Documentation

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn