Docs Menu

Docs HomeMongoDB Manual



Ends the current authentication session. This function has no effect if the current session is not authenticated.


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 users or $external, you must issue db.logout() against this database in order to successfully log out.


Use the use <database-name> helper in the interactive mongo shell, or the following db.getSiblingDB() in the interactive shell or in mongo shell scripts to change the db object:

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

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


db.logout() function provides a wrapper around the database command logout.

←  db.listCommands()db.printCollectionStats() →
Share Feedback
© 2023 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2023 MongoDB, Inc.