MongoDB Authentication CommandsThe authentication command is using the authentication mechanism known as x.509. When we use the mongo shell, we can use the db.auth() helper as follows: Syntax: In the earlier version of Mongo Shell, we can specify the password directly. Still, starting with version 4.2, we can use the passwordPrompt() method with various user authentication or management methods/ command to prompt for the password without specifying the password directly. In the earlier version we will use db.auth() method as: Syntax: MongoDB getnonce commandThe getnone command is used to generate the one-time password for authentication. The client gets disconnected before the operation completes if the client has been issued the getnonce. MongoDB logout commandThe logout command terminates the current authenticated running session when used as follows: Syntax: MongoDB allows users to have access to another database, and we must call logout while using the same database context that we are authenticated to. For Example - If you are verified to any database, you must issue a log out for that database to successfully logout from there. Example: when we set the database context and database object, we can use the logout command to log out from the database as follows: Next TopicMongoDB User Management Commands |