AI 에이전트의 경우: 문서 인덱스는 https://www.mongodb.com/ko-kr/docs/llms.txt에서 사용할 수 있으며, 모든 페이지의 마크다운 버전은 어떤 URL 경로에 .md를 추가하여 사용할 수 있습니다.
Docs Menu

db.grantRolesToUser() (mongosh 메서드)

db.grantRolesToUser(username, roles, writeConcern)

사용자에게 추가 역할을 부여합니다.

중요

Mongo쉬 방법

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

데이터베이스 명령에 대해서는 grantRolesToUser 명령을 참조하십시오.

MongoDB API 드라이버의 경우 언어별 MongoDB 드라이버 설명서를 참조하세요.

The db.grantRolesToUser() method uses the following syntax:

db.grantRolesToUser( "<username>", [ <roles> ], { <writeConcern> } )

The db.grantRolesToUser() method takes the following arguments:

Parameter
유형
설명

user

문자열

역할을 부여할 대상이 될 사용자의 이름입니다.

roles

배열

사용자에게 부여할 추가 역할의 배열입니다.

writeConcern

문서

선택 사항입니다. 작업에 대한 쓰기 고려 수준입니다. 쓰기 고려 사양을 참조하세요.

roles 필드에서 기본 제공 역할사용자 정의 역할을 모두 지정할 수 있습니다.

To specify a role that exists in the same database where db.grantRolesToUser() runs, you can either specify the role with the name of the role:

"readWrite"

또는 다음과 같이 문서로 역할을 지정할 수도 있습니다.

{ role: "<role>", db: "<database>" }

다른 데이터베이스에 존재하는 역할을 지정하려면 문서를 사용하여 역할을 지정합니다.

The db.grantRolesToUser() method wraps the grantRolesToUser command.

이 메서드는 다음 환경에서 호스팅되는 배포에서 사용할 수 있습니다.

중요

이 명령은 MongoDB Atlas 클러스터에서 지원되지 않습니다. 모든 명령에 대한 Atlas 지원에 관해 자세히 알아보려면 지원되지 않는 명령을 참조하세요.

If run on a replica set, db.grantRolesToUser() is executed using "majority" write concern by default.

해당 데이터베이스에 역할을 부여하려면 데이터베이스에 grantRole 작업이 있어야 합니다.

다음 역할이 있는 products 데이터베이스에는 accountUser01 사용자가 지정됩니다.

"roles" : [
{ "role" : "assetsReader",
"db" : "assets"
}
]

The following db.grantRolesToUser() operation gives accountUser01 the readWrite role on the products database and the read role on the stock database.

use products
db.grantRolesToUser(
"accountUser01",
[ "readWrite" , { role: "read", db: "stock" } ],
{ w: "majority" , wtimeout: 4000 }
)

이제 products 데이터베이스의 accountUser01 사용자에게는 다음 역할이 있습니다.

"roles" : [
{ "role" : "assetsReader",
"db" : "assets"
},
{ "role" : "read",
"db" : "stock"
},
{ "role" : "readWrite",
"db" : "products"
}
]
이 페이지 평가하기