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因为MongoDB允许在一个数据库中定义的用户在另一个数据库上拥有权限,所以您必须在使用与您身份验证相同的数据库上下文时调用db.logout()while using the same database context that you authenticated to.db.logout()。If you authenticated to a database such as如果您通过了usersor$external, you must issuedb.logout()against this database in order to successfully log out.users或$external等数据库的身份验证,则必须对此数据库发出db.logout()才能成功注销。Example示例Use the在use <database-name>helper inmongosh, or the followingdb.getSiblingDB()method in an interactivemongoshsession or inmongoshshell scripts to change thedbobject:mongosh中使用use <database-name>辅助程序,或在交互式mongosh会话或mongoshshell脚本中使用以下db.getSiblingDB()方法来更改db对象:db = db.getSiblingDB('<database-name>')When you have set the database context and设置数据库上下文和dbobject, you can use thedb.logout()to log out of database as in the following operation:db对象后,可以使用db.logout()注销数据库,如下操作所示:db.logout()db.logout()function provides a wrapper around the database command函数为数据库命令logout.logout提供了一个包装器。
Compatibility兼容性
This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
Note
This command is supported in all MongoDB Atlas clusters. 所有MongoDB Atlas集群都支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令。
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本