문서 메뉴

문서 홈애플리케이션 개발MongoDB 매뉴얼

db.getRole()

이 페이지의 내용

  • 정의
  • 필요한 액세스 권한
  • 예제
  • 역할 상속 정보 표시
  • 역할 권한 표시
  • 인증 제한 표시
db.getRole(rolename, args)

이 역할이 권한을 상속하는 역할을 반환합니다. 선택적으로 이 메서드는 모든 역할의 권한을 반환할 수도 있습니다.

역할이 포함된 데이터베이스에서 db.getRole() 를 실행합니다. 이 명령은 사용자 정의 역할기본 제공 역할 모두에 대한 정보를 검색할 수 있습니다.

db.getRole() 메서드는 다음 매개변수를 허용합니다.

매개변수
유형
설명
rolename
문자열
역할의 이름입니다.
args
문서
선택 사항입니다. 추가 인수를 지정하는 문서입니다.

args 문서는 다음과 같은 선택적 필드를 지원합니다.

필드
유형
설명
showAuthenticationRestrictions
부울

선택 사항입니다. 출력에 인증 제한 사항을 포함하려면 이 필드를 true로 설정합니다. 인증 제한은 이 역할을 가진 사용자가 연결할 수 있는 IP 주소를 나타냅니다.

기본적으로 이 필드는 false이며, 이는 db.getRole() 출력에 인증 제한이 포함되지 않음을 의미합니다.

showBuiltinRoles
부울
선택 사항입니다. 출력에 기본 제공 역할을 포함하려면 이 필드를 true 로 설정합니다. 기본적으로 이 필드는 false로 설정되어 있으며 rolesInfo: 1의 출력은 사용자 정의 역할만 표시합니다.
showPrivileges
부울
선택 사항입니다. 다른 역할에서 상속된 권한과 직접 정의된 권한을 모두 포함하여 역할 권한을 표시하려면 이 필드를 true로 설정합니다. 기본적으로 명령은 이 역할이 권한을 상속하는 역할만 반환하고 특정 권한은 반환하지 않습니다.

db.getRole()rolesInfo 명령을 래핑합니다.

역할 정보를 확인하려면 해당 역할을 명시적으로 부여 받았거나 역할 데이터베이스에 viewRole 조치가 있어야 합니다.

이 섹션의 예에서는 db.getRoles를 사용하는 방법을 보여줍니다.

다음 작업은 products 데이터베이스에 정의된 associate 역할에 대한 역할 상속 정보를 반환합니다.

use products
db.getRole( "associate" )

출력 예시:

{
_id: 'products.associate',
role: 'associate',
db: 'products',
roles: [ { role: 'readWrite', db: 'products' } ],
inheritedRoles: [ { role: 'readWrite', db: 'products' } ],
isBuiltin: false
}

다음 작업은 products 데이터베이스에 정의된 역할 associate에 대한 역할 상속 정보 및 권한을 반환합니다.

use products
db.getRole( "associate", { showPrivileges: true } )

출력 예시:

{
_id: 'products.associate',
role: 'associate',
db: 'products',
privileges: [
{
resource: { db: 'products', collection: '' },
actions: [ 'bypassDocumentValidation' ]
}
],
roles: [ { role: 'readWrite', db: 'products' } ],
inheritedRoles: [ { role: 'readWrite', db: 'products' } ],
inheritedPrivileges: [
{
resource: { db: 'products', collection: '' },
actions: [ 'bypassDocumentValidation' ]
},
{
resource: { db: 'products', collection: '' },
actions: [
'changeStream',
'collStats',
'compactStructuredEncryptionData',
'convertToCapped',
'createCollection',
'createIndex',
'dbHash',
'dbStats',
'dropCollection',
'dropIndex',
'find',
'insert',
'killCursors',
'listCollections',
'listIndexes',
'planCacheRead',
'remove',
'renameCollectionSameDB',
'update'
]
}
],
isBuiltin: false
}

다음 작업은 products 데이터베이스에 정의된 associate 역할에 대한 역할 상속 정보 및 인증 제한을 반환합니다.

use products
db.getRole( "associate", { showAuthenticationRestrictions: true } )

출력 예시:

{
_id: 'products.associate',
role: 'associate',
db: 'products',
roles: [ { role: 'readWrite', db: 'products' } ],
authenticationRestrictions: [
[ { clientSource: [ '198.51.100.0' ] } ]
],
inheritedRoles: [ { role: 'readWrite', db: 'products' } ],
inheritedAuthenticationRestrictions: [
[ { clientSource: [ '198.51.100.0' ] } ]
],
isBuiltin: false
}
← db.dropAllRoles()