db.dropUser()
On this page本页内容
Definition定义
db.dropUser(username, writeConcern)-
Removes the user from the current database.从当前数据库中删除用户。Importantmongosh Method
This page documents a
mongoshmethod. This is not the documentation for database commands or language-specific drivers, such as Node.js.For the database command, see the
dropUsercommand.For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
For the legacy对于遗留的mongoshell documentation, refer to the documentation for the corresponding MongoDB Server release:mongoshell文档,请参阅相应MongoDB Server版本的文档:Thedb.dropUser()method takes the following arguments:db.dropUser()方法采用以下参数:Parameter参数Type类型Description描述usernamestring The name of the user to remove from the database.要从数据库中删除的用户的名称。writeConcerndocument Optional.可选的。The level of write concern for the operation. See Write Concern Specification.操作的写入关注级别。请参阅写入关注规范。Thedb.dropUser()method wraps thedropUsercommand.db.dropUser()方法包装dropUser命令。Before dropping a user who has the在删除具有userAdminAnyDatabaserole, ensure you have at least another user with user administration privileges.userAdminAnyDatabase角色的用户之前,请确保至少有另一个具有用户管理权限的用户。
Behavior行为
Replica set副本集
If run on a replica set, 如果在副本集上运行,db.dropUser() is executed using "majority" write concern by default.db.dropUser()在默认情况下使用"majority"写入关注执行。
Required Access所需访问权限
You must have the 必须对数据库执行dropUser action on a database to drop a user from that database.dropUser 操作才能从该数据库中删除用户。
Example实例
The following 以下db.dropUser() operation drops the reportUser1 user on the products database.db.dropUser()操作会将products数据库中的reportUser1用户删除。
use products
db.dropUser("reportUser1", {w: "majority", wtimeout: 5000})