CentOS Stream9 MongoDB 6のユーザーを作成する方法
環境
CentOS Stream release 9
MongoDB v6.0.2
操作方法
1.MongoDBを起動します
# sudo systemctl start mongod
2.MongoDBに接続します
# mongosh Current Mongosh Log ID: 63441da20a1671cef2a8fb78 Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.6.0 Using MongoDB: 6.0.2 Using Mongosh: 1.6.0 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ To help improve our products, anonymous usage data is collected and sent to MongoDB periodically (https://www.mongodb.com/legal/privacy-policy). You can opt-out by running the disableTelemetry() command. test>
3.ユーザーを作成します
データベースadminに切り替えます
test> use admin switched to db admin
以下のコマンドでユーザーを作成します
コマンド
db.createUser(
{
user: "arkuser",
pwd: passwordPrompt(),
roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
}
)
操作例
admin> db.createUser(
... {
... user: "arkuser",
... pwd: passwordPrompt(),
... roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ]
... }
... )
Enter password
****{ ok: 1 }
作成したユーザーでログインします
# mongosh -u arkuser -p –authenticationDatabase admin
Enter password: ****
Current Mongosh Log ID: 634423d15293a5be8c907178 Connecting to: mongodb://<credentials>@127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&authSource=admin&appName=mongosh+1.6.0 Using MongoDB: 6.0.2 Using Mongosh: 1.6.0 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ test>