Passing the connection URL
- Last Updated: July 12, 2021
- 2 minute read
- DataDirect Connectors
- JDBC
- MongoDB 6.1
- Documentation
After setting the CLASSPATH, the required connection information needs to be passed in the form of a connection URL. The following example includes the properties required for connecting with user ID and password authentication.
Connection URL Syntax
The connection URL takes the following form:
jdbc:datadirect:mongodb://host:port;AuthenticationDatabase=auth_db;
DatabaseName=database;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.
- auth_db
-
(recommended) specifies the database in which your user ID was created. This value allows you to explicitly select a set of credentials and permissions when the same user ID was created in multiple databases on the server.
Note: We recommend specifying a value for this option when using user ID and password authentication (AuthenticationMethod=userIdPassword) to ensure that the correct permissions are used for your connection.
- 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.
- 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.
The following example connection string includes the properties required for connecting with user ID and password authentication.
Connection conn = DriverManager.getConnection
("jdbc:datadirect:mongodb://myserver:27017;AuthenticationDatabase=mydb2;
DatabaseName=mydb;user=jsmith;password=secret;");