MongoDB issue 정리

MongoDB Authentication failed

minikube에서 mongodb에 접속하고나서 명령어를 실행한 순간 인증을 요구하는 에러가 발생한다.

kubectl exec -it -n litmus chaos-mongodb-0 -- mongosh --authenticationDatabase admin -u root -p 1234

MongoServerError: command listDatabases requires authentication

MongoServerError: Authentication failed.
use admin
db.auth("root")

Enter password
1234

****{ ok: 1 }

Mongodb secondary to master

mongodb에서 master로 접근하기 위해 다음 명령어를 실행했다. 그러나 예측했던 primary가 아닌 secondary로 출력이 된다.

docker exec -it m1 mongo -port 27015

해당 명령어를 통해 현재 primary를 실행하고 있는 노드를 확인한 후 primary로 접속했다.

rs.hello().primary 
m2:27016 
docker exec -it m2 mongo -port 27016

Ref
https://velog.io/@stpnlsw/mongoDB-Authentication-failed-해결
https://pycoding.tistory.com/entry/몽고dbmongoDB-Authentication-failed
https://planbs.tistory.com/entry/MongoDB-%EC%9D%B8%EC%A6%9Dauthorization-%EC%B6%94%EA%B0%80%ED%95%98%EA%B8%B0
https://www.mongodb.com/ko-kr/docs/mongodb-shell/reference/options/#authentication-options