logout
logout
- The
logout
command terminates the currentauthenticated session:
- { logout: 1 }
Note
If you’re not logged in and using authentication, logout
has no effect.
Because MongoDB allows users defined in one database to haveprivileges on another database, you must call logout
whileusing the same database context that you authenticated to.
If you authenticated to a database such as users
or$external
, you must issue logout
against thisdatabase in order to successfully log out.
Example
Use the use <database-name>
helper in the interactivemongo
shell, or the following db.getSiblingDB()
in the interactive shell or in mongo
shell scripts tochange the db
object:
- db = db.getSiblingDB('<database-name>')
When you have set the database context and db
object, youcan use the logout
to log out of database as in thefollowing operation:
- db.runCommand( { logout: 1 } )