Home > Web Front-end > JS Tutorial > Mongoose Documentation

Mongoose Documentation

WBOY
Release: 2024-08-06 18:45:22
Original
447 people have browsed it

Mongoose Documentation

install mangoose

npm install mongoose
Copy after login

.
.
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));
Copy after login

.
.
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);
Copy after login

.
.
To create a students
ex:controllers folder

console.log('hi')
Copy after login

The above is the detailed content of Mongoose Documentation. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template