inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지

몽구스 실전 프로젝트

mongodb Asio socket.set_option error

781

moonshot

작성한 질문수 1

0

안녕하세요.

개정 3판 Node.js 교과서 8-6 몽구스 실전 프로젝트에서 처음 프로젝트를 시작할 시, cd ch8/8.6/learn-mongoose 하여 폴더에 들어간 이후 npm start 에서 막혔습니다. terminal 상으로는 돌아가지만, localhost:3002로 접속했을때, 제대로 접속되지 않고 로딩창만 뜹니다.

저는 현재, intel MAC, Vertura 13.1 버전 쓰고 있으며, 노드 JS는 v18.12.1, mongodb는 6.0.4버전 쓰고있습니다.

에러 메세지는 다음과 같습니다.

몽고디비 연결 에러 MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
at Connection.openUri (/Users/jisu/Downloads/nodejs-book-master/node_modules/mongoose/lib/connection.js:825:32)
at /Users/jisu/Downloads/nodejs-book-master/node_modules/mongoose/lib/index.js:409:10
at promiseOrCallback (/Users/jisu/Downloads/nodejs-book-master/node_modules/mongoose/lib/helpers/promiseOrCallback.js:11:14)
at Mongoose._promiseOrCallback (/Users/jisu/Downloads/nodejs-book-master/node_modules/mongoose/lib/index.js:1262:10)
at Mongoose.connect (/Users/jisu/Downloads/nodejs-book-master/node_modules/mongoose/lib/index.js:408:20)
at connect (/Users/jisu/Downloads/nodejs-book-master/ch8/8.6/learn-mongoose/schemas/index.js:7:12)
at Object.<anonymous> (/Users/jisu/Downloads/nodejs-book-master/ch8/8.6/learn-mongoose/app.js:18:1)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32) {
reason: TopologyDescription {
type: 'Unknown',
servers: Map(1) { 'localhost:27017' => [ServerDescription] },
stale: false,
compatible: true,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
setName: null,
maxElectionId: null,
maxSetVersion: null,
commonWireVersion: 0,
logicalSessionTimeoutMinutes: null
},
code: undefined
}

 

MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 를 구글링하여 몇가지를 시도해봤는데,

1번째, MONGO_URI=mongodb://localhost:27017/blog 를 MONGO_URI=mongodb://127.0.0.1:27017/blog 로 바꾸어 해결한 사례가 있어 ch8/8.6/learn-mongoose/schemas 폴더의 index.js에서mongoose.connect('mongodb://root:1234@localhost:27017/admin' 를 mongoose.connect('mongodb://root:1234@127.0.0.1:27017/admin', 로 바꾸었지만, → 해결되지 않았습니다.

2번째, terminal에 mongod를 쳐서 error가 난 부분을 살펴보니,

{"t":{"$date":"2023-02-07T00:55:42.260+09:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"-","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2023-02-07T00:55:42.263+09:00"},"s":"I",  "c":"NETWORK",  "id":4915701, "ctx":"-","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":17},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":17},"outgoing":{"minWireVersion":6,"maxWireVersion":17},"isInternalClient":true}}}
{"t":{"$date":"2023-02-07T00:55:42.280+09:00"},"s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"thread1","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2023-02-07T00:55:42.285+09:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","namespace":"config.tenantMigrationDonors"}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","namespace":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"ShardSplitDonorService","namespace":"config.tenantSplitDonors"}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I",  "c":"CONTROL",  "id":5945603, "ctx":"thread1","msg":"Multi threading initialized"}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I",  "c":"CONTROL",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":64400,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"iMac.local"}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"6.0.4","gitVersion":"44ff59461c1353638a71e710f385a566bcd2f547","modules":[],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"22.2.0"}}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"E",  "c":"NETWORK",  "id":23024,   "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Permission denied"}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"F",  "c":"ASSERT",   "id":23091,   "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":40486,"file":"src/mongo/transport/transport_layer_asio.cpp","line":1126}}
{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"F",  "c":"ASSERT",   "id":23092,   "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}

이 부분에서, 에러인 부분인

{"t":{"$date":"2023-02-07T00:55:42.286+09:00"},"s":"E",  "c":"NETWORK",  "id":23024,   "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Permission denied"}}

이 부분이 에러일 것같다는 생각에, 구글링을 하던 중

/tmp/mongodb-27017.sock 파일의 접근권한을 변경하거나 파일 삭제 후 서비스를 재시작하면 정상적으로 mongodb가 부팅된다.

는 글을 보고, sudo rm -rf /tmp/mongodb-27017.sock로 sock 파일을 삭제해봤지만, 똑같은 결과였습니다.

ls -l /tmp/mongodb-27017.sock로 확인했을때, 삭제된 것도 확인했습니다.

3번째, terminal에 brew services list 로 mongodb상태를 확인해보려고 하였습니다.

Name              Status     User File
mongodb-community error  512 jisu ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
mysql             none            
postgresql@14     none    

로 나오는 것을 보아 mongodb가 제대로 작동되지 않고 있어서 에러가 발생하는 것으로 추측했습니다.

 brew services start mongodb-community

의 결과로,

Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/502 /Users/jisu/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist` exited with 5.

가 나와서, 이를 해결하기 위해 mongodb-community를 완전히 지우고, brew cleanup까지 한 다음 다시 깔아봤지만 달라진 바는 없었습니다. 이전 강좌까지 mongodb에서 데이터베이스 생성하는 CRUD 실습할때까지만 해도 문제없었는데, 갑자기 에러를 벹어내네요.. 3일동안 이 문제를 해결하려 힘써봤는데 도저히 감이 안잡혀서 질문드립니다.

 

node.js mongodb mysql socket.io express nodejs Socket.io typescript jwt

답변 1

0

제로초(조현영)

sudo mongod로 실행하시면 permission 문제 안 나지 않나요?

깃헙 질문

0

82

2

강의 1-1 수업노트의 로드맵 링크가 작동하지 않습니다.

0

78

1

aws - lightsail 이용 관련

0

59

1

4강 http 서버 만들때 ESM방식으로 해도 될까요?

0

83

2

모듈 사용 시 단점이 있나요?

0

84

1

node.js 버전 및 typescript 적용 문의

0

95

2

12.7. 방장기능(강퇴) 질문드립니다.

0

80

2

12.7 socket.js코드 그대로 뱃겨서 했는데, socket.request.session.color가안나오네요

0

69

1

12.7 코드 그대로 뱃겨서 햇는데 스샷같이 오류가뜹니다.

0

77

2

12.7.1스스로 해보기 질문되나요

0

95

3

시퀄라이즈 실습하기 질문드립니다.

0

197

9

<7-5. 시퀄라이즈 사용하기>수업 질문 드립니다.

0

98

2

크롬에서 user id를 인풋에 입력하고 등록하면 404 에러처리 페이지가 뜹니다.

0

114

2

구매 결제관련 질문입니다 !

0

123

1

다수의 supertest 가 실행될 때 force:true로 인한 DB 초기화 문제

0

134

2

node 설치 방법이 전혀다르게 바뀐것 같습니다.

0

152

2

12강 깃허브에 있는 12.7 chat.html 복붙했는데 css오류

0

123

2

무료/프리미엄 동시 소유 시 질문

0

117

1

비주얼 스튜디오 코드로 계속 진행해도 괜찮을까요?

0

136

2

10강 cors에러 localhost:4000으로 접속했을때 에러

1

159

2

webstorm 해결할 수 없는 변수 문제

0

155

2

혹시 몽고DB 쓸거면 MySQL 강의 스킵해도 되나요?

0

149

2

LightSail 실행 중 오류 질문드립니다!

0

204

2

RedisStore 사용법 질문

0

134

2