logout
Deprecated since version 5.0.自5.0版以来已弃用。
Attempting to use the 尝试使用logout command will write an error message to the log once per logout attempt.logout命令将在每次注销尝试时向日志中写入一条错误消息。
This command will be removed in a future release.此命令将在将来的版本中删除。
The logout command terminates the current authenticated session:logout命令终止当前经过身份验证的会话:
{ logout: 1 }
If you're not logged in and using authentication, 如果您没有登录并使用身份验证,则logout has no effect.logout无效。
Because MongoDB allows users defined in one database to have privileges on another database, you must call 因为MongoDB允许在一个数据库中定义的用户拥有对另一个数据库的权限,所以您必须在使用经过身份验证的同一数据库上下文时调用logout while using the same database context that you authenticated to.logout。
If you authenticated to a database such as 如果您对数据库(如用户或users or $external, you must issue logout against this database in order to successfully log out.$external)进行了身份验证,则必须对此数据库发出logout命令才能成功注销。
Use the 在use <database-name> helper in mongosh, or the following db.getSiblingDB() method in an interactive mongosh session or in mongosh shell scripts to change the db object:mongosh中使用<database name>helper,或者在交互式mongosh会话或mongosh shell脚本中使用以下db.getSiblingDB()方法来更改db对象:
db = db.getSiblingDB('<database-name>')
When you have set the database context and 设置了数据库上下文和db object, you can use the logout to log out of database as in the following operation:db对象后,可以使用logout注销数据库,如下操作所示:
db.runCommand( { logout: 1 } )