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 에서는 필요하지 않습니다.
그러나 분산환경은 그렇지 않습니다. 따라서 분산 환경에서 다수 데이터에 대한 다수 연산이 동시에 요청될 때 데이터(document)의 ACID(Atomicty, Consistency, Isolation, Durabilty)를 지키기 위해 transaction이 사용됩니다.
mongoose transaction 해결 방법
mongodb replica set을 구축하는 방법은 아래의 포스팅과 같습니다.
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 환경입니다.
amkorousagi-money.tistory.com
참고 자료
Transactions — MongoDB Manual
Docs Home → MongoDB Manual In MongoDB, an operation on a single document is atomic. Because you can use embedded documents and arrays to capture relationships between data in a single document structure instead of normalizing across multiple documents an
www.mongodb.com
댓글