AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

db.revokeRolesFromUser()(mongoshメソッド)

db.revokeRolesFromUser()

現在のデータベース上のユーザーから 1 つ以上のロールを削除します。

重要

mongosh メソッド

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

データベースコマンドについては、revokeRolesFromUser コマンドを参照してください。

MongoDB API ドライバーについては、各言語の「MongoDB ドライバーのドキュメント」を参照してください。

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

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

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

Parameter
タイプ
説明

user

string

ロールを取り消すユーザーの名前。

roles

配列

ユーザーから削除するロール。

writeConcern

ドキュメント

任意。 操作の 書込み保証( write concern ) のレベル。 詳しくは、 書込み保証(write concern) の仕様を参照してください。

rolesフィールドでは、組み込みロールユーザー定義ロールの両方を指定できます。

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

"readWrite"

または、次のように、ドキュメントを使用してロールを指定することもできます。

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

別のデータベースに存在するロールを指定するには、 ドキュメントを使用してロールを指定します。

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

このメソッドは、次の環境でホストされている配置で使用できます。

重要

このコマンドは、MongoDB Atlas クラスターではサポートされていません。すべてのコマンドに対する Atlas のサポートについては、「サポートされていないコマンド」を参照してください。

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

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

データベースのロールを取り消すには、データベースに対してrevokeRoleアクションが必要です。

productsデータベース内のaccountUser01ユーザーには次のロールがあります。

"roles" : [
{ "role" : "assetsReader",
"db" : "assets"
},
{ "role" : "read",
"db" : "stock"
},
{ "role" : "readWrite",
"db" : "products"
}
]

The following db.revokeRolesFromUser() method removes the two of the user's roles: the read role on the stock database and the readWrite role on the products database, which is also the database on which the method runs:

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

productsデータベース内のユーザーaccountUser01ユーザーに残りのロールが 1 つだけになりました。

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