Databases are created and exist after inserting the first document into a collection in the database. Databases and collections are created implicitly; however, creating a database or collection object in your client does not create a database or collection. use <db> does not create new database files. >> 요약 미숙한 영어로 간단히 요약하면 첫 데이터가 들어올때까지 db와 collection은 암시적으로 생성된다. use 명령어는 새로운 db파일을 생성하지 않는다.
> mongosh
> use newdb
> db.auth("abc", passwordPrompth())
mongosh 만으로 접속하면 test로 연결이 되는데 여기서 db.auth()를 하면 인증이 안된다. 이유는 1. 유저 생성에서 유저를 생성할 때 newdb에서 했기 때문이다. newdb로 이동해서 인증을 하면 접속이 된다.
- robo3t 같은 외부 툴에서 접속이 안된다.
1. 방화벽을 열자
# 방화벽에 열린 포트확인
> firewall-cmd --zone=public --list-ports
# 포트 영구 등록
> firewall-cmd --permanent --add-port=27017/tcp
# 방화벽 재시작
> firewall-cmd --reload
2. /etc/mongod.conf 수정
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.