保存document收藏時出現此錯誤ValidatorError: 路徑id是必需的。這是我的代碼 https://codesandbox.io/s/lively-tree-hd0foconst BlogPost = new Schema({ id: { type: String, required: true, unique: true }, empid: String, date: Date});BlogPost.pre("save", function(next) { var blog = this; console.log(); var data = `${blog.empid}-${blog.date}`; blog.id = crypto .createHash("md5") .update(data) .digest("hex"); next();});當我嘗試保存數據時出現錯誤。一種pp.get("/saveData", async () => { try { var blog = new BlogPostModel({ empid: "test123", date: "19-Jul-2019" }); console.log("before save"); let saveBlog = await blog.save(); //when fail its goes to catch console.log(saveBlog); //when success it print. console.log("saveBlog save"); } catch (error) { console.log(error); }});
獲取錯誤 ValidatorError: Path `id` 是必需的。在 mongo 數據庫中
慕哥9229398
2021-10-14 17:07:15