Get the App
SLTechnology News&Howtos  ›  Database  › 

Example Analysis of MongoDB Database role

Shulou Source: shulou.com Published: 2022-05-31 14:29:30 11月10日 Update

This article shares a sample analysis of MongoDB database roles. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

Database User Roles

read

CollStats,dbHash,dbStats,find,killCursors,listIndexes,listCollections

readWrite

CollStats,ConvertToCapped,CreateCollection,DbHash,DbStats,

DropCollection,CreateIndex,DropIndex,Emptycapped,Find,

Insert,KillCursors,ListIndexes,ListCollections,Remove,

RenameCollectionSameDB,update

Database Administration Roles

dbAdmin

collStats,dbHash,dbStats,find,killCursors,listIndexes,listCollections,

dropCollection and createCollection in system.profile

dbOwner

Roles: readWrite, dbAdmin,userAdmin

userAdmin

ChangeCustomData,ChangePassword,CreateRole,CreateUser,

DropRole,DropUser,GrantRole,RevokeRole,ViewRole,viewUser

Cluster Administration Roles

clusterAdmin

Roles: clusterManager, clusterMonitor, hostManager

clusterManager

AddShard,ApplicationMessage,CleanupOrphaned,FlushRouterConfig,

ListShards,RemoveShard,ReplSetConfigure,ReplSetGetStatus,

ReplSetStateChange,Resync,

EnableSharding,MoveChunk,SplitChunk,splitVector

clusterMonitor

connPoolStats,cursorInfo,getCmdLineOpts,getLog,getParameter,

getShardMap,hostInfo,inprog,listDatabases,listShards,netstat,

replSetGetStatus,serverStatus,shardingState,top

collStats,dbStats,getShardVersion

hostManager

applicationMessage,closeAllDatabases,connPoolSync,cpuProfiler,

diagLogging,flushRouterConfig,fsync,invalidateUserCache,killop,

logRotate,resync,setParameter,shutdown,touch,unlock

Backup and Restoration Roles

backup

Provides insert,update permissions in the admin database mms.backup document

List all databases: listDatabases

List all collection indexes: listIndexes

Provide query actions for: find

* Non-systematic collections

* System collection: system.indexes, system.namespaces, system.js

* Collections: admin.system.users and admin.system.roles

restore

Non-system collections, system.js, admin.system.users, and admin.system.roles, as well as version 2.6 of system.users, provide the following permissions:

collMod,createCollection,createIndex,dropCollection,insert

List all databases: listDatabases

system.users :find,remove,update

All-Database Roles

readAnyDatabase

Provides read-only permissions in all databases: read

List all databases in the cluster: listDatabases

readWriteAnyDatabase

Provide all database read and write permissions: readWrite

List all databases in the cluster: listDatabases

userAdminAnyDatabase

Provide all user data management privileges: userAdmin

Cluster:authSchemaUpgrade,invalidateUserCache,listDatabases

admin.system.users and admin.system.roles:

collStats,dbHash,dbStats,find,killCursors,planCacheRead

createIndex,dropIndex

dbAdminAnyDatabase

Provide all database administrator privileges: dbAdmin

List all databases in the cluster: listDatabases

Superuser Roles

root

Roles: dbOwner, userAdmin, userAdminAnyDatabase

readWriteAnyDatabase, dbAdminAnyDatabase,

userAdminAnyDatabase,clusterAdmin

Internal Role

__system

Take any action on any database in the cluster

Initialize user data:

1) Manage Account

use admin

db.createUser({

user:'admin',

pwd:'123456',

roles:[

{role:'userAdminAnyDatabase',db:'admin'},

{role:'dbAdminAnyDatabase',db:'admin'},

{role:'clusterMonitor',db:'admin'}

]

})

2) Application account

use mydb

db.createUser({

user:'mydb',

pwd:'123456',

roles:[{role:"dbOwner",db:"svideo"},

{role:"clusterAdmin",db:"admin"} ]

})

or

use mydb

db.createUser({

user:'mydb',

pwd:'123456',

roles:[{role:'readWrite',db:'svideo'}]

})

Command Line Landing:

mongo 127.0.0.1/svideo -uvdb -p

Or:

mongo --host 47.93.118.56:27017 --authenticationDatabase svideo -u vdb -p

Thank you for reading! About "MongoDB database role example analysis" This article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Tags: Data databases permissions roles clusters systems administration examples analysis content more users articles accounts good practical commands data management documents articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MySQL macOS Xiaomi Shulou Technology