LoginSignup
1
2

More than 5 years have passed since last update.

忘れがちなMongoDBの操作メモ

Last updated at Posted at 2017-09-25

ユーザを作成する

ユーザ情報例

Database:somedatabase
ID: user
PW: password

somedatabaseにユーザを作成する。

use somedatabase
db.createUser(
  {
    user:"user",
    pwd:"password",
    roles:[
       { 
           "role" : "dbOwner",
            "db" : "somedatabase"
       }
    ]
  } 
);

ユーザに足りないroleを追加する。

adminにDB管理をつけておく。

db.grantRolesToUser( "user", [ "dbAdmin" ])

後で困るのでrootもつけておく。

db.grantRolesToUser( "user", [ "root" ])

同時に付けることも可能。

db.grantRolesToUser( "user", [ "root", "dbAdmin",  { role: "read", db: "comment" }])

他付けるroleに迷ったら全Role値を参考:https://docs.mongodb.com/manual/reference/built-in-roles/#built-in-roles

ユーザを削除する。

削除したいデータベースをuseして、dropUserをかけていく。

use somodatabase
db.dropUser('useraname')
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2