MongoDB5.0.6でユーザーを作成する方法

環境
debian 11.2
MongoDB 5.0.6

操作方法
1.mongoコマンド実行
# mongo

2.adminDBを利用する
> use admin
switched to db admin

3.ユーザーとパスワードとロール(root スーパーユーザー)を追加

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
> db.createUser({user:"mongo", pwd:"12345678a", roles:["root"]})
Successfully added user: { "user" : "mongo", "roles" : [ "root" ] }
> db.createUser({user:"mongo", pwd:"12345678a", roles:["root"]}) Successfully added user: { "user" : "mongo", "roles" : [ "root" ] }
> db.createUser({user:"mongo", pwd:"12345678a", roles:["root"]})
Successfully added user: { "user" : "mongo", "roles" : [ "root" ] }

4.退出
> exit
bye

5.作成ユーザーとパスワードで接続します
ユーザーを指定してログイン

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# mongo -u mongo
MongoDB shell version v5.0.6
Enter password: #パスワード入力
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("f98b0ceb-abbe-4e0f-a92a-df121afdcbc4") }
MongoDB server version: 5.0.6
# mongo -u mongo MongoDB shell version v5.0.6 Enter password: #パスワード入力 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("f98b0ceb-abbe-4e0f-a92a-df121afdcbc4") } MongoDB server version: 5.0.6
# mongo -u mongo
MongoDB shell version v5.0.6
Enter password:  #パスワード入力
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("f98b0ceb-abbe-4e0f-a92a-df121afdcbc4") }
MongoDB server version: 5.0.6

 

MongoDB

Posted by arkgame