db.logout()Obsoleto desde la versión 5.0.
Attempting to use the
db.logout()method will write an error message to the log once per logout attempt.Este método será eliminado en una versión futura.
Termina la sesión de autenticación actual. Esta función no tiene efecto si la sesión actual no está autenticada.
Nota
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
usersor$external, you must issuedb.logout()against this database in order to successfully log out.Ejemplo
Use the
use <database-name>helper inmongosh, or the followingdb.getSiblingDB()method in an interactivemongoshsession or inmongoshshell scripts to change thedbobject:db = db.getSiblingDB('<database-name>') When you have set the database context and
dbobject, you can use thedb.logout()to log out of database as in the following operation:db.logout() db.logout()function provides a wrapper around the database commandlogout.
Compatibilidad
Este método está disponible en implementaciones alojadas en los siguientes entornos:
- MongoDB Atlas: El servicio totalmente gestionado para implementaciones de MongoDB en la nube
Nota
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
MongoDB Enterprise: La versión basada en suscripción y autogestionada de MongoDB
MongoDB Community: La versión de MongoDB con código fuente disponible, de uso gratuito y autogestionada.