w3resource

MongoDB: db.logout() method

db.logout

The db.logout() method is used to ends an authenticated session. db.loadServerScripts() loads all scripts in the system.js collection for the current database into the mongo shell session. If you’re not logged in and using authentication, db.logout() has no effect.

Syntax:

db.loadServerScripts()

NOTE

MongoDB now 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.

Example: MongoDB: db.logout() method

In the following example the database-name myinfo have used in the interactive mongo shell and after setting the database context and db object, the db.logout() have been used to log out of database as in the following operation:

db=db.getSiblingDB('myinfo')
db.logout();

Output:

> db=db.getSiblingDB('myinfo')
myinfo
> db.logout();
{ "ok" : 1 }

Retrieve the restaurants data from here

Previous: db.listCommands() method
Next: db.printCollectionStats() method



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/mongodb/shell-methods/database/db-logout.php