mongoose的簡單使用方法 上一篇中使用的"mongoose"有許多定義好的方法可以使用,最好先宣告幾個方法統一呼叫才會比較方便。請跟著下面的流程好好的重構一下程式碼! 個人習慣針對資料庫的操作會統一宣告在一個資料夾內保管,所以首先建立資料夾"models"在建立放置資料庫模型的js檔"schemaModels.js"然後依照練習用的範例資料庫一一建立模型 models\schemaModels.js let mongoose = require ( 'mongoose' ); const accounts = new mongoose.Schema({ account_id : { type : Number }, …
閱讀完整內容前情題要 上一篇我們註冊了雲端DB並且完全沒有碰程式碼,現在就讓我們來開始動程式碼。 該用哪個套件處理mongodb?? mongodb VS mongoose 可以參考這篇文章 Performance Difference in Mongoose vs MongoDB Native Driver ,這邊會選擇使用mongoose,因為使用上比較簡單。如果使用mongodb速度會比較快因為他能控制到相當底層的東西。本篇使用的是mongoose所以沒辦法使用範例程式碼,請使用下面的程式碼。 首先安裝"mongoose" npm i --save mongodb app.js 略 const mongoose = require ( 'mongoose' ); co…
閱讀完整內容
追蹤我們