--- tags: Node.js 直播班 --- # 檢核點 - 第三週 **重點觀念:** Express MVC **回覆參考:** ``` ... ``` --- - 可以把 __v 屬性移除,我們會盡可能管控吐給前端的資料,確保哪些才是前端會需要的資料 - handle 相關可以建立一個資料夾區分一下 handle - 整體來講不太建議用解構的方式取出 controllers,主要原因是較難區分是哪裡來的 controllers,所以還是會建議保持原本的引入會較好 - 因最終作業會是貼文動態牆,不能傳送空的貼文內容,修改貼文建議可以另新增判斷是否有傳入 data.content;或者可以在 findByIdAndUpdate 加入第三個參數 { runValidators: true },讓 findByIdAndUpdate 也可以跑 Schema 驗證規則,可以參考[這篇文章](https://israynotarray.com/nodejs/20220301/1465076357/)哦 - ~~新增及修改時,如果輸入的不是 JSON 格式會出現錯誤,可以參考[這裡](https://github.com/expressjs/express/issues/4065#issuecomment-536151203)提供的方式來判斷哦~~ (第五週補充) 補充: Mongoose Schema 要轉換成 Modal 的時候,通常會建議首字大寫,而且在儲存資料時 Mongoose 會自動幫你轉換成全小寫 + 復數,如: User 變成 users 這個可以稍微注意一下,因為這個在官方文件上是有說明的 > The first argument is the singular name of the collection your model is for. Mongoose automatically looks for the plural, lowercased version of your model name. Thus, for the example above, the model Tank is for the tanks collection in the database. 出處:https://mongoosejs.com/docs/models.html#compiling <small>批改時若遇到問題或常見錯誤歡迎助教們新增上來</small>