- Reference >
- Database Commands >
- Authentication Commands >
- logout
logout¶
-
logout
¶ The
logout
command terminates the current authenticated session:Note
If you’re not logged in and using authentication,
logout
has no effect.Because MongoDB allows users defined in one database to have privileges on another database, you must call
logout
while using the same database context that you authenticated to.If you authenticated to a database such as
users
or$external
, you must issuelogout
against this database in order to successfully log out.Example
Use the
use <database-name>
helper in the interactivemongo
shell, or the followingdb.getSiblingDB()
in the interactive shell or inmongo
shell scripts to change thedb
object:When you have set the database context and
db
object, you can use thelogout
to log out of database as in the following operation: