발견한오류
C:\Users\SSAFY\Desktop\nodejs\boilerplate\node_modules\mongoose\lib\model.js:517 throw new MongooseError('Model.prototype.save() no longer accepts a callback');
원인
오류 메시지 MongooseError: Model.prototype.save() no longer accepts a callback는 최신 버전의 Mongoose에서 save() 메소드가 더 이상 콜백 함수를 받지 않는다,
해결방안
기존 코드
app.post('/register', async (req, res) => {
const user = new User(req.body)
user.save((err,doc)=>{
if(err) return res.json({success:false,err})
return res.status(200).json({
success:true,})
})
})
수정코드
app.post('/register', async (req, res) => {
const user = new User(req.body);
try {
const doc = await user.save();
res.status(200).json({ success: true });
} catch (err) {
res.json({ success: false, err });
}
});
'오늘의뻘짓' 카테고리의 다른 글
리액트 설치시 오류 “npm install” 오류 발생할때 :- npm i npm ERR! code EEXIST npm ERR! syscall rename (0) | 2024.03.16 |
---|---|
맥 OS 새 터미널 안열리는 오류 (0) | 2023.12.28 |
[따라하며 배우는 노드js] 13강 오류 (2) | 2023.11.24 |
[따라하며 배우는 노드js] 12강 오류 (0) | 2023.11.24 |
0722 장고 홈페이지 설정오류 (프로그래머스 [Day14] Web Application with Django) (0) | 2022.07.22 |