Docs Menu

dropUser

dropUser

Removes the user from the database on which you run the command.

Tip

mongoshでは、このコマンドはdb.dropUser()ヘルパー メソッドを通じて実行することもできます。

ヘルパー メソッドはmongoshユーザーには便利ですが、データベースコマンドと同じレベルの情報は返されない可能性があります。 便宜上必要ない場合、または追加の戻りフィールドが必要な場合は、 データベースコマンドを使用します。

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

  • MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです

重要

This command is not supported in M10+ clusters. For more information, see Unsupported Commands.

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

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

このコマンドの構文は、次のとおりです。

db.runCommand(
{
dropUser: "<user>",
writeConcern: { <write concern> },
comment: <any>
}
)

コマンドには次のフィールドがあります:

フィールド
タイプ
説明

dropUser

string

The name of the user to delete. You must issue the dropUser command while using the database where the user exists.

writeConcern

ドキュメント

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

comment

any

任意。このコマンドに添付するユーザー指定のコメント。設定すると、このコメントは以下の場所にこのコマンドの記録と合わせて表示されます。

コメントには、有効な BSON 型(string, integer, object, array など)を使用できます。

userAdminAnyDatabase ロールを持つユーザーを削除する前に、ユーザー管理特権を持つ別のユーザーが少なくとも 1 人いることを確認してください。

データベースからユーザーを削除するには、データベースに対して dropUser アクションが必要です。

The following sequence of operations in mongosh removes reportUser1 from the products database:

use products
db.runCommand( {
dropUser: "reportUser1",
writeConcern: { w: "majority", wtimeout: 5000 }
} )