정의
grantPrivilegesToRole명령이 실행되는 데이터베이스에 정의 된 사용자 정의 역할에 추가 권한 을 할당합니다.
팁
In
mongosh, this command can also be run through thedb.grantPrivilegesToRole()helper method.Helper methods are convenient for
mongoshusers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.The
grantPrivilegesToRolecommand uses the following syntax:
db.runCommand( { grantPrivilegesToRole: "<role>", privileges: [ { resource: { <resource> }, actions: [ "<action>", ... ] }, ... ], writeConcern: { <write concern> }, comment: <any> } )
호환성
이 명령은 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
중요
This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.
MongoDB Enterprise: MongoDB의 구독 기반 자체 관리 버전
MongoDB Community: MongoDB의 소스 사용 가능 무료 자체 관리 버전
명령 필드
명령에는 다음과 같은 필드가 있습니다.
필드 | 유형 | 설명 |
|---|---|---|
| 문자열 | 권한을 부여할 사용자 정의 역할의 이름입니다. |
| 배열 | 역할에 추가할 권한입니다. 권한 형식은 |
| 문서 | |
| any | 선택 사항. 이 명령에 첨부할 사용자 제공 코멘트입니다. 설정되면 이 설명은 다음 위치에서 이 명령의 레코드와 함께 표시됩니다.
댓글은 유효한 모든 BSON types (문자열, 정수, 객체, 배열 등)이 될 수 있습니다. |
행동
역할의 권한은 역할이 생성된 데이터베이스에 적용됩니다. admin 데이터베이스에서 생성된 역할에는 모든 데이터베이스 또는 클러스터에 적용되는 권한이 포함될 수 있습니다.
필요한 액세스 권한
권한을 부여하려면 권한이 대상으로 하는 데이터베이스에 grantRole 작업이 있어야 합니다. 여러 데이터베이스 또는 cluster 리소스에 대한 권한을 부여하려면 admin 데이터베이스에 대한 grantRole 작업이 있어야 합니다.
예시
The following grantPrivilegesToRole command grants two additional privileges to the service role that exists in the products database:
use products db.runCommand( { grantPrivilegesToRole: "service", privileges: [ { resource: { db: "products", collection: "" }, actions: [ "find" ] }, { resource: { db: "products", collection: "system.js" }, actions: [ "find" ] } ], writeConcern: { w: "majority" , wtimeout: 5000 } } )
privileges 배열 의 첫 번째 권한 을 통해 사용자는 products 데이터베이스 의 모든 비시스템 컬렉션을 검색 할 수 있습니다. 이 권한 은 컬렉션 과 같은 system.js 시스템 컬렉션 에 대한 쿼리를 허용하지 않습니다. 이러한 시스템 컬렉션에 액세스 을 부여하려면 privileges 배열 에 액세스 을 명시적으로 프로비저닝합니다. 자체 관리 배포서버에 대한 리소스 문서를 참조하세요.
두 번째 find system.js 권한은 모든 데이터베이스의 collection에 대한 조치를 명시적으로 허용합니다.