db.logout()

db.logout()

Deprecated since version 5.0.自5.0版以来已弃用

Attempting to use the db.logout() method will write an error message to the log once per logout attempt.尝试使用db.logout()方法将在每次注销尝试时向日志写入一条错误消息。

This method will be removed in a future release.此方法将在以后的版本中删除。

Ends the current authentication session. 结束当前身份验证会话。This function has no effect if the current session is not authenticated.如果当前会话未经过身份验证,则此函数无效。

Note注意

If you're not logged in and using authentication, db.logout() has no effect.如果您没有登录并使用身份验证,db.logout()将无效。

Because MongoDB allows users defined in one database to have privileges on another database, you must call db.logout() while using the same database context that you authenticated to.因为MongoDB允许在一个数据库中定义的用户对另一个数据库拥有权限,所以必须在使用您进行身份验证的相同数据库上下文时调用db.logout()

If you authenticated to a database such as users or $external, you must issue db.logout() against this database in order to successfully log out.如果对users$external等数据库进行了身份验证,则必须对此数据库发出db.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>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 db.logout() to log out of database as in the following operation:设置数据库contextdb对象后,可以使用db.logout()注销数据库,如下操作所示:

db.logout()

db.logout() function provides a wrapper around the database command logout.函数提供了数据库命令logout的包装。

←  db.listCommands()db.printCollectionStats() →