This string includes the properties used to connect with TLS/SSL encryption and user ID and password authentication. For more information, see "TLS/SSL data encryption."

jdbc:datadirect:mongodb://host:port;CryptoProtocolVersion=protocol;DatabaseName=database;
EncryptionMethod=[SSL | requestSSL];HostNameInCertificate=host_name;KeyPassword=key_password;
KeyStore=key_store;TrustStore=trust_store;TrustStorePassword=ts_password;
ValidateServerCertificate=vsc_value;User=username;Password=password;[property=value[;...]];

where:

host

specifies the name or the IP address of the MongoDB server to which you want to connect.

For example, myserver.
port

specifies the port number of the server listener. The default is 27017.

protocol

(optional) specifies a cryptographic protocol or comma-separated list of cryptographic protocols that can be used when SSL is enabled. For example, TLSv1.3,TLSv1.2.

database
(optional) specifies the name of the database to which you want to connect. This value is used as the default qualifier for unqualified table names in SQL queries.
Important: This value is case-insensitive if you have access privileges to query the list of databases on the server. If you do not have access, this value is case-sensitive.
host_name
(optional) specifies the host name to be used to validate the certificate. The HostNameInCertificate property provides additional security against man-in-the-middle (MITM) attacks by ensuring that the server the driver is connecting to is the server that was requested.
key_password
(optional) specifies the password of the keystore file, if your database server is configured for SSL client authentication. Alternatively, you can set the corresponding Java system property javax.net.ssl.keyStorePassword, in lieu of this property.
key_store
(optional) specifies the location of the keystore file, if your database server is configured for SSL client authentication. Alternatively, you can set the corresponding Java system property, javax.net.ssl.keyStore, in lieu of this property.
trust_store
(optional) specifies the location of the truststore file used for SSL server authentication. Alternatively, you can set the corresponding Java system property, javax.net.ssl.trustStore, in lieu of this property.
ts_password
(optional) specifies the password of the truststore file used for SSL server authentication. Alternatively, you can set the corresponding Java system property, javax.net.ssl.trustStorePassword, in lieu of this property.
vsc_value
(optional) specify true to validate certificates sent by the database server.
user
(optional) specifies the user name that is used to connect to the MongoDB database. For example, jsmith.
password
(optional) specifies the password used to connect to your MongoDB database.
property=value
specifies connection property settings. Multiple properties are separated by a semi-colon.
Note: The User and password properties are not required to be stored in the connection string. They can also be passed separately by the application.

The following example connection string includes the minimum properties required for connecting with data encryption, and user ID and password authentication.

Connection conn = DriverManager.getConnection
  ("jdbc:datadirect:mongodb://myserver:27017;DatabaseName=mydb;EncryptionMethod=SSL;User=jsmith;
         Password=secret;");