[MongoDB] couldn't connect to server 127.0.0.1:27017, connection attempt failed

rin·2020년 5월 28일
0
post-thumbnail

mongoDB를 실행하기 위해서 bash에서 mongod를 입력하고 새로운 탭에서 mongo를 입력하니 다음과 같은 오류가 발생하였다.

couldn't connect to server 127.0.0.1:27017, connection attempt failed

구글링해보니 mongodb 서버가 실행되지 않아서 연결이 안되는 경우란다 🤔

다시 mongod를 실행해보고 출력을 읽어보니 서버가 실행이 안되고 있는게 맞았다.

NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file., terminating

즉, /data/db 라는 디렉토를 찾을 수 없으니 --dbpath 옵션을 사용하거나 설정 파일에 storage.dbpath를 추가하라고 한다.

  1. sudo mkdir /data/db를 통해 디렉토리를 생성하고
  2. mongod --dbpath data/db 실행

위와 같이 ~$로 나오지 않으면 성공

다른 탭을 열어서 mongo 명령어로 클라이언트를 열어보자

> 로 커맨드 입력창이 변경되었다면 db 커맨드를 날렸을 때 (어떤 데이터베이스도 생성되지 않은 경우) test 라는 결과가 출력되면 mongoDB 연결해 성공한 것이다.

profile
🌱 😈💻 🌱

0개의 댓글