Docs HomeMongoDB Manual

logout

On this page本页内容

Definition定义

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.此命令将在将来的版本中删除。

Note

This command was used when you could log in as multiple users on a single physical connection. 当您可以在单个物理连接上以多个用户身份登录时,会使用此命令。Because this is no longer possible, running logout may cause connections to fail. 因为这已经不可能了,所以运行logout可能会导致连接失败。Going forward, you can achieve the same results by closing your connection.展望未来,你可以通过关闭你的连接来获得同样的结果。

Syntax语法

The command has the following syntax:该命令具有以下语法:

db.runCommand(
{
logout: 1
}
)

Example实例

Note

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 logout while using the same database context that you authenticated to.因为MongoDB允许在一个数据库中定义的用户对另一个数据库拥有权限,所以您必须在使用身份验证的同一数据库上下文时调用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.如果您通过了数据库(如users$external)的身份验证,则必须针对该数据库发出logout,才能成功注销。

Example

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中的use <database-name>助手,或在交互式mongosh会话或mongosh shell脚本中使用以下db.getSiblingDB()方法来更改数据库对象:

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 } )