db.logout()自版本 5.0 起已弃用。
Attempting to use the
db.logout()method will write an error message to the log once per logout attempt.此方法将在未来版本中删除。
结束当前身份验证会话。 如果当前会话未经身份验证,则此函数无效。
注意
If you're not logged in and using authentication,
db.logout()has no effect.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.If you authenticated to a database such as
usersor$external, you must issuedb.logout()against this database in order to successfully log out.例子
Use the
use <database-name>helper inmongosh, or the followingdb.getSiblingDB()method in an interactivemongoshsession or inmongoshshell scripts to change thedbobject: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.logout() db.logout()function provides a wrapper around the database commandlogout.
兼容性
此方法可用于以下环境中托管的部署:
- MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
注意
所有 MongoDB Atlas 集群都支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本