- Reference >
- Database Commands >
- Authentication Commands >
- logout
logout¶
-
logout¶ Deprecated since version 5.0.
Attempting to use the
logoutcommand will write an error message to the log once per logout attempt.This command will be removed in a future release.
The
logoutcommand terminates the current authenticated session:Note
If you’re not logged in and using authentication,
logouthas no effect.Because MongoDB allows users defined in one database to have privileges on another database, you must call
logoutwhile using the same database context that you authenticated to.If you authenticated to a database such as
usersor$external, you must issuelogoutagainst this database in order to successfully log out.Example
Use the
use <database-name>helper inmongosh, or the followingdb.getSiblingDB()method in an interactivemongoshsession or inmongoshshell scripts to change thedbobject:When you have set the database context and
dbobject, you can use thelogoutto log out of database as in the following operation: