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.此命令将在将来的版本中删除。NoteThis 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实例
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.users
或$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
中的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 } )