」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 貓鼬文檔

貓鼬文檔

發佈於2024-08-06
瀏覽:929

Mongoose Documentation

安裝 mangoose

npm install mongoose


.
使用 mongoose
連接到 mongodb 例如:app.js

const mongoose=require('mongoose');
mongoose
    .connect('url');
    .then(res=>app.listen(3000));
    .catch(err=>console.log(err));


.
創建模式
例如:模型資料夾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);


.
創建學生
例如:控制器資料夾

console.log('hi')
版本聲明 本文轉載於:https://dev.to/munisekharudavalapat/mongoose-documentation-jdc?1如有侵犯,請聯絡[email protected]刪除
最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3