- authenticate
- Authenticates using the X.509 authentication mechanism. When using - mongosh, use the- db.auth()helper as follows:- Tip- You can use the - passwordPrompt()method in conjunction with various user authentication management methods and commands to prompt for the password instead of specifying the password directly in the method or command call. However, you can still specify the password directly as you would with earlier versions of the- mongoshell.- db.auth( "username", passwordPrompt() ) - In earlier versions, to use the - db.auth()method, specify the password:- db.auth( "username", "password" ) 
Compatibility
This command is available in deployments hosted in the following environments:
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud 
Important
This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.
- MongoDB Enterprise: The subscription-based, self-managed version of MongoDB 
- MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB 
Behavior
Client Disconnection
If the client that issued authenticate disconnects before the operation
completes, MongoDB marks authenticate for termination using
killOp.