mongodb not authorized? how to create database in mongodb

Posted by nopsled
2018.04.18 11:01 데이터베이스

[root@dataking01 data]# mongo

MongoDB shell version v3.4.9

connecting to: mongodb://127.0.0.1:27017

MongoDB server version: 3.4.9

> use testdb

switched to db testdb

> db.createCollection("test_collection")

{

"ok" : 0,

"errmsg" : "not authorized on testdb to execute command { create: \"test_collection\" }",

"code" : 13,

"codeName" : "Unauthorized"

}

>


위와 같이 authorized가 안되어 있어서 컬렉션도 못만들고 난리가 났다.



[root@dataking01 data]# ps -ef | grep mongo

root     11876     1  0 10:57 ?        00:00:01 /usr/bin/mongod --auth -f /etc/mongod.conf

root     12127  8518  0 11:01 pts/0    00:00:00 grep mongo

[root@dataking01 data]# kill -9 11876

[root@dataking01 data]# 


서비스 확인해주고 11876 죽여준다음에


[root@dataking01 data]# /usr/bin/mongod -f /etc/mongod.conf

about to fork child process, waiting until server is ready for connections.

forked process: 12173

child process started successfully, parent exiting

[root@dataking01 data]# 


--auth flag 빼버리고 mongodb를 시작해준다.


그리고 mongo로 접속해서 use database_name, db.createCollection("collection_name") 해주면 된다.


이거 했다고해서 --auth flag를 다시 넣어주는거 깜빡하지말자.. 골로간다



[root@dataking01 data]# ps -ef | grep mongo

root     12173     1  0 11:02 ?        00:00:00 /usr/bin/mongod -f /etc/mongod.conf

root     12232  8518  0 11:03 pts/0    00:00:00 grep mongo

[root@dataking01 data]# kill -9 12173

[root@dataking01 data]#

[root@dataking01 data]#

[root@dataking01 data]# /usr/bin/mongod --auth -f /etc/mongod.conf

about to fork child process, waiting until server is ready for connections.

forked process: 12278

child process started successfully, parent exiting

[root@dataking01 data]# 


--auth flag를 줘야 혹여나 안털린다


오늘의 삽질 끝.

이 댓글을 비밀 댓글로