[MongoDB] 연결 안 될때 확인할 것 3가지

쥬롬의 코드착즙기·2022년 12월 22일
0

TIL : Today I learned

목록 보기
9/10
post-thumbnail

몽고디비는 새로 할 때마다 연결이 안된다. ;;
원인은 대개 다음과 같다.

1. MongooseServerSelectionError: ... Make sure your current IP address is on your Atlas cluster's IP whitelist

  • 에러메시지
MongooseServerSelectionError: Could not connect to any
servers in your MongoDB Atlas cluster. One common reason is
that you're trying to access the database from an IP that
isn't whitelisted. Make sure your current IP address is 
on your Atlas cluster's IP whitelist:
https://docs.atlas.mongodb.com/security-whitelist/
  • 원인: IP 주소 변동
    학교에서 하다가 집에서 하면 안된다. DB에 접속할 수 있게 허용된 IP주소가 따로 있기 때문이다.
  • 해결방법: IP Address Access 추가해주기

MongoDB Atlas에서 Network Access로 들어가서 +ADD IP ADDRESS를 클릭한다.

ADD IP ADDRESS 창 안에 ADD CURRENT IP ADDRESS를 클릭해주면 자동으로 현재 IP주소가 Access List Entry에 입력된다. 입력되면 Confirm해준다.

2. MongoServerError: bad auth : authentication failed

  • 에러메시지
MongoServerError: bad auth : authentication failed
  • 원인
    db접속 url이 틀렸거나, 그 url 안에 들어가는 username과 password가 틀렸음
  • 해결방법
    db url 한번 더 복붙해주고 username, password 체크해주기

Database 탭에서 접속하려는 cluster에 connect를 눌러준다.

그럼 이 창이 뜨는데, visual studio code에서 코드 복붙할 거라서 두 번째 Connect your application을 눌러준다.

나오는 코드를 복사해 준다.

vscode에 복붙한다. 이때 < password >에서 <>를 빼고 비밀번호를 입력해야 한다. cluster0에 접속하는 username 이 user123이고 password가 pw456이면
mongodb+srv://user123:pw456@cluster0. ~~~
이런 식이어야 한다.

profile
코드를 짭니다...

0개의 댓글