본문 바로가기

전체 글150

req.body 가 비었을 때(empty) req.body empty 에러 내용 node fetch로 post 메서드로 request를 보냈는데 express에서 까보니 req.body가 비어있다. req.body empty 에러 원인 Content-Type 헤더를 안 적어서 req.body가 json인 줄 모른다. req.body empty 해결 방법 다음과 같이 Content-Type header도 적어준다. fetch(URL, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(body), }) .then((res) => { return res.json(); }) 2023. 5. 26.
MongoDB Compass Secondary node가 비었을 때 db.getMongo().setReadPref('secondary') readPreference: 'primary'MongoDB Compass Secondary node가 비었을 때 에러 내용MongoDB Compass로 Mongo Replica set의 Seconadry node에 연결하면 모두 비어있다. 에러 원인기본 설정이 secondary node에서 read operation을 명시적으로 허용하지 않는다. 해결 방법각 몽고 컨테이너에서mongosh use admin db.auth("id","pwd") db.getMongo().setReadPref('secondary') 디비 연결할 때 node에서readPreference: 'secondary' MongoDB Compass 에서 read 연산이 .. 2023. 5. 19.
spawn app crashed : 에러 메시지 없는 에러 잡기 spawn app crashed : 에러 메시지 없는 에러 잡기 spawn app crashed 에러 내용 node express에서는 크게 동기 에러와 비동기 에러가 있습니다. 이는 다음과 같이 각각 error handler와 wrapping을 통해 잡을 수 있습니다. ... app.use(handlingError); ... export const handlingError = (err, req, res, next) => { let httpCode = StatusCodes.INTERNAL_SERVER_ERROR; let data = { success: false, data: {}, error: err.name, message: err.message, detail: err.stack, }; logger.e.. 2023. 5. 15.
Error: Transaction numbers are only allowed on a replica set member or mongos Error: Transaction numbers are only allowed on a replica set member or mongos mongoose transaction 에러 내용 mongoose에서 transaction 및 session을 사용하려고 하면 위와 같은 오류가 출력됩니다. mongoose transaction 에러 원인 default 설정인 standalone은 mongoose session의 transaction 기능을 사용할 수 없습니다. 단일 서버에서는 다수 데이터에 대한 다수 연산이 동시에 요청되더라도 atomicty 등을 지키면서 연산을 수행할 수 있습니다. 따라서 transaction은 standalone 에서는 필요하지 않습니다. 그러나 분산환경은 그렇지 않습니다. 따라.. 2023. 5. 15.
MongoDB replica set 사용하기(with Docker Compose, Haproxy load balancer) MongoDB replica set 사용하기(with Docker Compose, Haproxy load balancer) MongoDB replica set 설명 production 환경을 위해 mongodb replica set을 사용합니다. MongoDB replica set 사용 방법 0. 환경 확인 저는 window 10 환경입니다. 일반적으로는 linux 계열의 OS에서 하시는 것을 추천합니다. (윈도우는 LF나 권한 및 소유 문제 등이 발생합니다.) 1. docker desktop을 설치 Install Docker Desktop on Windows docs.docker.com 2. docker-compose.yml 작성 # Use root/example as user/password cred.. 2023. 5. 15.
haproxy load balancer 중 /usr/local/etc/haproxy/haproxy.cfg: 'server mongo1' : could not resolve address 'mongo1' 또는 Failed to initialize server(s) addr. 2023-05-15 15:18:49 [ALERT] (1) : parsing [/usr/local/etc/haproxy/haproxy.cfg:20] : 'server mongo1' : could not resolve address 'mongo1'. 2023-05-15 15:19:09 [ALERT] (1) : parsing [/usr/local/etc/haproxy/haproxy.cfg:21] : 'server mongo2' : could not resolve address 'mongo2'. 2023-05-15 15:19:29 [ALERT] (1) : parsing [/usr/local/etc/haproxy/haproxy.cfg:22] : 'server mongo3' : could not resolve ad.. 2023. 5. 15.