db.logout()

  • db.logout()
  • Ends the current authentication session. This function has no effectif the current session is not authenticated.

Note

If you’re not logged in and using authentication, db.logout()has no effect.

Because MongoDB allows users defined in one database to haveprivileges on another database, you must call db.logout() whileusing the same database context that you authenticated to.

If you authenticated to a database such as users or$external, you must issue db.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:

  1. db = db.getSiblingDB('<database-name>')

When you have set the database context and db object, youcan use the db.logout() to log out of database as in thefollowing operation:

  1. db.logout()

db.logout() function provides a wrapper around thedatabase command logout.