node.js와 mongoDB연결
mongodb+srv://<name>:<password>@cluster0.uazu7ta.mongodb.net/<DBname>?retryWrites=true&w=majority
새로운 폴더에서 다시 시작하려니까, 안깔려있는 패키지들이 많아서 시간을 잡아먹었다.
전과 같은 에러로, router파일 밑에 module.exports = router;를 쓰지않아서 발생
TypeError: Router.use() requires a middleware function but got a Object
user.schema에서 정의한 { Id }를 써줬어야 했는데, { userId }라는 변수를 선언해서 값이 undifined가 나왔다.
객체구조분해할당을 잘못 이해한 까닭이다.
TypeError: Cannot destructure property 'userId' of 'res.locals.user' as it is null.
ObjectParameterError: findOne()에 대한 매개변수 "필터"는 객체여야 합니다. 파라미터는 2입니다.
ObjectParameterError: Parameter "filter" to findOne() must be an object, got 2
post를 정의할때 find로 찾았을땐 [{ }]형태여서 post.userId는 undified였다.
post를 정의할때 findOne을 사용하니 { }형태여서 값이 나왔다.
같은 값 중복에러(삭제 후 재생성시 발생)
MongoServerError: E11000 duplicate key error collection: test.posts index: postId_1 dup key: { postId: 2 }